clocking function clock () in C and C + +

Source: Internet
Author: User

In MSDN, the check for the clock function is defined as follows:

clock_t clock (void);

Returns the time that the program consumes the CPU from startup to function calls. This function returns the number of CPU clock ticks (clock ticks) from "Open this program process" to "call clock () function in program", called Wall Clock Time (Wal-clock) in MSDN, and returns 1 if the wall clock time is not desirable.

Where clock_t is the data type used to hold the time, it is defined as follows

#ifndef _clock_t_definedtypedef long clock_t; #define _CLOCK_T_DEFINED#ENDIF in the time.h file, a constant clocks_per_sec is also defined. It is used to indicate how many clock units are in a second, defined as follows: #define CLOCKS_PER_SEC ((clock_t) 1000) every 1 per thousand seconds (1 milliseconds), the value returned by the call to the clock () function is added 1. You can use the clock function to calculate how long it takes for your machine to run a loop or handle other events: clock_t start, end;double clocktime;

start = Clock ();

....... functions.
end = Clock ();
Clocktime = (double) (End-start))/clocks_per_sec;

clocking function clock () in C and C + +

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.