Sanda said:
You can use the clock() function to calculate the time. Just call it
before and after the function calls and substract the two values and
devide it buy CLK_TCK which is the systems pulse time.
eg:
#include<time.h>
#include said:
//other include files
void main()
UB. int main()
{clock_t start, end;
style?
//codes................
start=clock();
//your funcrion calls
end =clock();
printf("\n Time taken is %f seconds.\n",(end-start)/CLK_TCK);
without stdio.h, UB.
printf (
"\n Time taken is %f seconds.\n",(double)(end-start)/CLOCKS_PER_SEC
);
return 0;
for more information use the help files in your compiler. (I used the
Turbo c++ compiler for this).
The Turbo C++ compiler is a C++ compiler. Use GCC or something
that supports the C Standard.
/*
* @file: interval.c
*/
#include <stdio.h>
#include <limits.h>
#include <time.h>
int
main (int argc, char **argv)
{
clock_t start, /* start of timing */
end; /* end of timing */
int i; /* index */
/* (A)
* Start timing
*/
start = clock ();
/* (B)
* the code to time goes here.
* sample follows (warning:
* this may take a long time!):
*/
for (i = 0; i < INT_MAX; ++i)
printf ("%d\r", i);
/* (C)
* end timing
*/
end = clock ();
/* (D)
* display interval
*/
printf ("\nInterval: %.2f\n", (double)(end-start)/CLOCKS_PER_SEC);
return 0;
}
Regards,
Jonathan.