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.

The output of the above program is.