The clock() function is defined in the ctime header file. The clock() function returns the approximate processor time that is consumed by the program. The clock() time depends upon how the operating system allocate resources to the process that’s why clock() time may be slower or faster than the actual clock.
clock_t clock( void );
Parameters: This function does not accept any parameter.
Return Value: This function returns the approximate processor time that is consumed by the program and on failure function returns -1.
Below program illustrates the implementation of clock() function:
Processor time taken for multiplication: 0.006485 seconds Processor time taken in pow function: 0.022251 seconds
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- C program to print digital clock with current time
- Difference between user defined function and library function in C/C++
- How to call some function before main() function in C++?
- Function Overloading vs Function Overriding in C++
- How to call function within function in C or C++
- Difference between Virtual function and Pure virtual function in C++
- What happens when a virtual function is called inside a non-virtual function in C++
- arc function in C
- fma() function in C++
- log() function in C++
- exp() function C++
- div() function in C++
- Inline function in C
- putchar() function in C
- mbsrtowcs() function in C/C++
- isunordered() function in C++
- wctob() function in C++
- isinf() function in C++
- wcscoll() function in C++
- mbsinit() Function in C/C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.