Skip to contentSkip to conversation

displaying time_t values

DISCUSSION fabio 4 participants 4 messages Oct 22, 2005 – Oct 24, 2005

lore
Share & tools
lore

fabio

author
#0 lore raw

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

#1 lore raw
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
#2 lore raw
In reply to fabio

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

#3 lore raw
In reply to fabio
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]>