Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Thu, 02 May 2013 10:12:39 +0200
From: Jens Gustedt <jens.gustedt@...ia.fr>
To: musl@...ts.openwall.com
Subject: Re: sign (in)consistency between architectures

Am Mittwoch, den 01.05.2013, 22:47 -0400 schrieb Rich Felker:
> In any case, I think all of these issues are good arguments that
> nobodu should ever use clock_t or the clock() function...

Hm, AFAIR clock() is the only available function in C alone (including
C11) that gives access to something like the "processor time". C11 a
bit more of time handling to have access to something like a real time
clock, but for processor time clock() is the only one. (MS got that
wrong, but this is their problem.)

So I think it still makes sense to use it for "short" measures, not
for the whole run of a program. The standard suggests, I think, that
you'd take a point of measure before and after the interval that
interests you. For such a strategy to work you'd either have to know
that no overflow can reasonably occur (by having a wide type) or that
it may do no harm (by using an unsigned type).

I would prefer to have both worlds by using uint64_t (or directly the
underlying base type) uniformly. There is no reason to have it signed:

 - this is "processor time" and not wallclock time, so it should be
   monotonic, and not be affected by setting the system time
 - an application should always subtract the first value of a measure
   from the second
 - an application should never expect to be able to measure intervals
   that are longer than a few hours, and it can deduce the maximum
   time it has for a measure with CLOCKS_PER_SEC

Jens


-- 
:: INRIA Nancy Grand Est :: http://www.loria.fr/~gustedt/   ::
:: AlGorille ::::::::::::::: office Nancy : +33 383593090   ::
:: ICube :::::::::::::: office Strasbourg : +33 368854536   ::
:: ::::::::::::::::::::::::::: gsm France : +33 651400183   ::
:: :::::::::::::::::::: gsm international : +49 15737185122 ::




Download attachment "signature.asc" of type "application/pgp-signature" (199 bytes)

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.