clock() function in C Last Updated : 06 Oct, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report The clock() function in C returns the approximate processor time that is consumed by the program which is the number of clock ticks used by the program since the program started. The clock() time depends upon how the operating system allocates resources to the process that's why clock() time may be slower or faster than the actual clock. The C clock() function is defined in the <ctime> header file. The difference between the clock() value at the beginning of the program and the clock() value at the point where we want to measure the clock ticks is the number of clock ticks used by a program. The result can be converted to seconds using the CLOCKS_PER_SEC constant, which represents the number of clock ticks per second. Syntaxclock_t clock( void );ParametersThis function does not accept any parameter.Return ValueThis function returns the approximate processor time that is consumed by the program.This function returns -1 in case of failure.C Program to Illustrate the use of clock() Function C // C Program to Illustrate the use of clock() Function #include <math.h> #include <stdio.h> #include <time.h> int main() { float a; clock_t time_req; // Without using pow function time_req = clock(); for (int i = 0; i < 200000; i++) { a = log(i * i * i * i); } time_req = clock() - time_req; printf("Processor time taken for multiplication: %f " "seconds\n", (float)time_req / CLOCKS_PER_SEC); // Using pow function time_req = clock(); for (int i = 0; i < 200000; i++) { a = log(pow(i, 4)); } time_req = clock() - time_req; printf("Processor time taken in pow function: %f " "seconds\n", (float)time_req / CLOCKS_PER_SEC); return 0; } Output Processor time taken for multiplication: 0.005343 seconds Processor time taken in pow function: 0.010641 seconds Comment More infoAdvertise with us Next Article clock() function in C B bansal_rtk_ Follow Improve Article Tags : C++ CPP-Functions C-Functions Practice Tags : CPP Similar Reads asctime() function in C++ The asctime() function is defined in the ctime header file. The asctime() function converts the given calendar time of structure tm to a character representation i.e human readable form. Syntax: char* asctime(const struct tm * time_ptr); Parameter: This function accepts single parameter time_ptr i.e 1 min read strftime() function in C/C++ strftime() is a function in C which is used to format date and time. It comes under the header file time.h, which also contains a structure named struct tm which is used to hold the time and date. The syntax of strftime() is as shown below : size_t strftime(char *s, size_t max, const char *format, c 3 min read round() Function in C In the C language, the <math.h> header file contains the Standard Math Library that provides various mathematical functions, including the round() function. In this article, we will see how to use the round() function in C.What is round() in C?C round() is a built-in library function that roun 3 min read gmtime() Function in C The gmtime() function in C takes a pointer to type t_time value which represents type in seconds and converts it to struct tm. In this article, we will learn gmtime() Function in the C programming language. The struct tm type can hold the individual components of time in UTC(Universal Time Coordinat 2 min read localtime() function in C++ The localtime() function is defined in the ctime header file. The localtime() function converts the given time since epoch to calendar time which is expressed as local time. Syntax: tm* localtime(const time_t* time_ptr); Parameter: This function accepts a parameter time_ptr which represents the poin 1 min read Like