COMP20005 how to time a program
Some students have asked me how to time the running of a program. Essentially, the problem is how do we know the amount of time that a program takes to run. In C, you can use functions from the header file time.h to time your program. The program below shows how to do a simple timing of a program.
#include <stdio.h>
#include <time.h>
int main(int argc, char **argv) {
char name;
double howlong;
time_t start, end;
start = time(NULL);
printf("Enter your name: ");
scanf("%s", &name);
end = time(NULL);
howlong = difftime(end, start);
printf("You took %.3lf seconds, %s\n", howlong, &name);
return 0;
}
Categories: COMP20005, programming
Reblogged this on Gigable – Tech Blog.
Tried this code.. nice one..