How it works...
Define two variables, clocktickstart and clocktickend, of the clock_t data type, as they will be used to represent the processor time. The main idea of this program is to ascertain the time consumed during the execution of a function.
The clock function is invoked to know the number of clock ticks elapsed from the time the program is invoked. Assign the number of clock ticks returned to a clocktickstart variable. Then, invoke a somefunction() function, which includes a nested for loop. The idea of using nested loops is just to make the CPU invest some time in executing these loops. After the somefunction function is over, invoke the clock() function, and assign the number of clock ticks elapsed from the time the program is ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access