[uClibc] clock() for long-running process

Joakim Tjernlund joakim.tjernlund at lumentis.se
Mon May 10 16:08:35 UTC 2004


> >>>>> On Mon, 10 May 2004 16:15:49 +0200, "Joakim Tjernlund" <joakim.tjernlund at lumentis.se> said:
> 
> tjernlund> Suppose times() wrap to a negative value between t1 and
> tjernlund> t2. Then you have:
> tjernlund> diff = t2 - t1 = -x(t2) - y(t1) = < 0, right?
> 
> In this case, negative overflow will happen.
> 
>   t1: 2147483647 (0x7fffffff)
>   t2: -2147483648 (0x80000000)
>   diff = t2 - t1 = 1
> 
> No magic :-)

Right, I was under the impression that this type of overflow would
only work for unsigned integers. I was obviously wrong :(

To summarize: Using times() to measure elapsed time as shown below
works just fine, providing that that the time intervall is short
enough.

  clock_t t1,t2,diff; /* clock_t is a signed long */

  t1 = times(NULL);
  /* do work */
  t2 = times(NULL);
  diff = t2 - t1;

     Jocke



More information about the uClibc mailing list