Dear Alex (Pafu!),
A *very* portable alternative is GLIB.
http://developer.gnome.org/doc/API/glib/
I use it my code, and it is coded like this:
int main(int argc, char *argv[])
{
(...)
GTimer* stopwatch;
(...)
/* starting to time */
stopwatch = g_timer_new();
g_timer_start(stopwatch);
(... your code goes here ...)
m_print_time(stopwatch);
/* stopping and destroying the watch */
g_timer_stop(stopwatch);
g_timer_destroy(stopwatch);
(...)
}
void m_print_time(GTimer* stopwatch)
{
m_message("CPU time: %.2f secs. Effective time: %.2f secs.", (double)
clock() / CLOCKS_PER_SEC, g_timer_elapsed(stopwatch, NULL));
}
BTW, the GLIB is a beautiful library overall, with a lot of data
structures , event loops, and such other niceties.
This is how my solution looks...
---------------------------------------------
End of Simulation
---------------------------------------------
CPU time: 0.12 secs. Effective time: 0.14 secs.
About time resolution, In an i386 Linux the maximum I squeezed out is,
CPU time: 0.130000000000000 secs.
Effective time: 0.135188000000000 secs.
YMMV, Greetings,
Alan
On Tue, 23 Jul 2002, Aleksandar Donev wrote:
> Hello,
>
> Many UNIX Fortran compilers provide ETIME, a function that returns cpu
> elapsed time and also breaks it up into user and system time, but does
> not provide wall time. The NIST StopWatch Fortran library uses these
> times. I am not sure how much overhead or resolution the Linux ETIMEs
> provide (for example Lahey ships one with its compiler), but I am
> assuming it is not very good.
>
> Does anyone maybe know of a (relatively) portable C etime-equivalent,
> i.e. a timing function that returns at least user and system time, and
> preferably also wall-clock elapsed time, suitable to be used in
> profiling codes? Searching the web did not seem to give me many useful
> things.
>
> Thanks,
> Aleksandar
>
> --
> __________________________________
> Aleksandar Donev
> Complex Materials Theory Group (http://cherrypit.princeton.edu/)
> Princeton Materials Institute & Program in Applied and Computational Mathematics
> @ Princeton University
> Address:
> 419 Bowen Hall, 70 Prospect Avenue
> Princeton University
> Princeton, NJ 08540-5211
> E-mail: [log in to unmask]
> WWW: http://atom.princeton.edu/donev
> Phone: (609) 258-2775
> Fax: (609) 258-6878
> __________________________________
>
--
Alan Aspuru-Guzik Dios mueve al jugador, y éste, la pieza.
(510)642-5911 UC Berkeley ¿Qué Dios detrás de Dios la trama empieza
(925)422-8739 LLNL de polvo y tiempo y sueño y agonías? -Borges
|