0% found this document useful (0 votes)
44 views1 page

Measuring Time Complexity

This document discusses measuring time complexity in C/C++ programs. It describes the clock_t data type used to store processor time as CPU cycles, the clock() function that returns elapsed CPU cycles, and includes an example code showing how to use these to time a for loop.

Uploaded by

Rahul Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views1 page

Measuring Time Complexity

This document discusses measuring time complexity in C/C++ programs. It describes the clock_t data type used to store processor time as CPU cycles, the clock() function that returns elapsed CPU cycles, and includes an example code showing how to use these to time a for loop.

Uploaded by

Rahul Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

MEASURING TIME COMPLEXITY

clock_t – typedef -> uses long int (data type)

 Used to store the processor time interms of the number of CPU cycles
passes since the start of the process.

clock ()

 Returns the no. of elapsed CPU clock cycles.

time.h

 Header file contains all the predefined functions related to time


computation.

Return Type

 Return type of clock() is clock_t

Example

#include <time.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
int main(){
clock_t start, end, duration;
start = clock();
for(int i=0; i<60; i++){
log(100);
}
end = clock();
duration = (end - start);
printf("Processor cycles taken : %f cycles\n", (float)duration);
printf("Processor time taken : %f seconds\n",
(float)duration/CLOCKS_PER_SEC);
getch();
return 0;
}

You might also like