Created
September 29, 2013 08:35
-
-
Save sumanth232/04e2deaaaff4fe45c64f to your computer and use it in GitHub Desktop.
Measure the time of a function in seconds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<conio.h> | |
#include<time.h> | |
void fun() | |
{ | |
printf("fun() starts \n"); | |
printf("Press enter to stop fun \n"); | |
while(1) | |
{ | |
if (getchar()) | |
break; | |
} | |
printf("fun() ends \n"); | |
} | |
int main() | |
{ | |
// Calculate the time taken by fun() | |
clock_t t; | |
t = clock(); | |
fun(); | |
t = clock() - t; | |
double time_taken = ((double)t)/CLOCKS_PER_SEC; // in seconds | |
printf("fun() took %f seconds to execute \n", time_taken); | |
getch(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment