[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: timevar: further work

From: Akim Demaille
Subject: Re: timevar: further work
Date: Wed, 10 Oct 2018 07:29:47 +0200

Hi Bruno!

> Le 4 oct. 2018 à 18:51, Bruno Haible <address@hidden> a écrit :
> […]
> I would conclude that either times() or getrusage()+gettimeofday()
> provides the necessary functionality. Which one to choose? I think
> it's useful to compare the results on various platforms (regarding
> precision and behaviour regarding children processes), to see
> which one is better.

With respect to wall clock:

  - nothing in getrusage.  You suggest gettimeofday, but it’s
    not monotonic, clock_gettime(CLOCK_MONOTONIC,…) is a better
    option.  It has portability issues, but gnulib to the rescue.
  - times returns a clock_t, in system dependent clock ticks.
    Resolution is unclear, but I think I understood from various
    place that it’s typically 1µs.

With respect to what you called multiplicity (i.e., time spent
in subprocesses or threads):

- getrusage offers two choices:
  - RUSAGE_SELF: the calling process and its threads.
  - RUSAGE_CHILDREN: main and subprocesses that have been wait’ed.
  - Linux offers RUSAGE_THREAD, which is just about the current
    thread.  I don’t think we care about this.

- times offers the same options:
  - tms_utime/tms_stime: user/sys CPU time of the calling process.
  - tms_cutime/tms_cstime: user/sys sum of the tms_stime/tms_cstime
    of wait’ed child processes.

With respect to precision:

- getrusage: 1µs on modern platforms, possibly 1ms
- times: clock ticks (as for its usr/sys times), so I believe, 1µs
   in practice

With respect to portability:

 - getrusage is handled by gnulib
 - times too, but AFAICT, only for Windows (which is probably
   the sign that’s it’s more portable than getrusage.

It seems that both choices are fairly equivalent.  That’s what I
can see looking at macOS and GNU/Linux.  I have no idea about the
other platforms.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]