Calculate the time taken by a function in C and explain with example
We can calculate the time taken by the process using the clock () function. This function is available in time.h header file.
By calling the clock function at the function start and the end of the code And be follow the below steps to calculate the time taken by the process, please find the pseudo-code.
Following is a sample C program where we measure the time taken by mySampleFunction (). The function mySampleFunction () waits for enter key press to terminate.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// A function that terminates when enter key is pressed