displaying time_t values
hello,
I would like to know how to display the full seconds and miliseconds transacurrent since 2 points in a program.
main()
{
time_t t1_t2;
(void)time(&t1);
cpu_intensive_function();
(void)time(&t2);
printf("the full time spent in the process is:");
// how should i display it ? ej: 51,56745 seconds ot 1024,04546 seconds
}
Thanks,
fabolo
Quoted 2 lines · fabio
I would like to know how to display the full seconds and miliseconds transacurrent since 2 points in a program.
difftime(t2, t1)
But time won't give you msec resolution.
Signature · 3 lines
Michael Iatrou Electrical and Computer Engineering Dept. University of Patras, Greece
In case u find the function is over in shorer time,simply run the same function in a loop for n times and later divide the total time by n.Hope that was useful.
Quoted 23 lines · fabio
hello,
I would like to know how to display the full seconds and miliseconds transacurrent since 2 points in a program.
main(){ time_t t1_t2; (void)time(&t1); cpu_intensive_function(); (void)time(&t2); printf("the full time spent in the process is:"); // how should i display it ? ej: 51,56745 seconds ot 1024,04546 seconds}
Thanks,
fabolo
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 12 lines · fabio
I would like to know how to display the full seconds and miliseconds transacurrent since 2 points in a program.
main(){ time_t t1_t2; (void)time(&t1); cpu_intensive_function(); (void)time(&t2); printf("the full time spent in the process is:"); // how should i display it ? ej: 51,56745 seconds ot 1024,04546 seconds
Quoted 1 line
}
time() only provides second resolution. You need to use gettimeofday() to get better resolution.
Signature · 1 line
Glynn Clements <[email protected]>