-
timing your code
Is there a way to time your code
eg..
main()
{
starttime();
do some stuff.....
endtime();
totaltime= endtime-starttime; //or whatever..
}
So that the time that you end up with is in milliseconds?
I'm more looking for a usable function here. I've tired using clock(), and time(NULL) but neither seem to want to give me milliseconds. Any help would be appreciated.
-
Code:
#include <stdio.h>
#include <time.h>
int main ( void )
{
clock_t s, e;
s = clock();
/* Do stuff */
e = clock();
printf ( "%u\n", e - s );
return 0;
}
-Prelude
-
This is what's coming out...
@n=0 ->0
@n=32 ->20000
@n=128 ->1040000
Are these values representing CPU ticks or do they have actual value when it comes to time....
eg. @n=32 it's 20 milliseconds?
and @n=128 it's 1040 milliseconds or 1.04 seconds?
thanks in advance for any help..
-
Hi!
Look here.
You have to learn to inform yourself about standard functions, because programmers often donīt know them exactly.
You can get the information simply by searching for example at Google (e.g. "c+reference+time.h").
klausi
-
Thank you much klausi, I've got something I can use now.
Your right about not understanding functions enough, I'll do a bit more research next time;)
~mike~