(time) function: big and small intervals

Q&A's, tips, howto's
Locked
Fritz
Posts: 66
Joined: Sun Sep 27, 2009 12:08 am
Location: Russia

(time) function: big and small intervals

Post by Fritz »

I have tested today some scripts operating with some millions files, and I have noticed two strange things about (time) function.

1. Big intervals.

Code: Select all

> (time (sleep 3600000))
1,844674407e+016
1,8e+016ms = 595 000 years, hehe.

2. Small intervals.

Code: Select all

> (time (read-file "100_13.txt") 70)
0
> (time (read-file "100_13.txt") 80)
0
> (time (read-file "100_13.txt") 90)
15,625
> (time (read-file "100_13.txt") 90)
0
> (time (read-file "100_13.txt") 90)
15,625
15,625 = 1/64 second. So, I think, 15,625 ms — is a minimal quant, that can be measured with (time) command. But today I have seen results like 0,010 ms and so on… Only idea I have, there is some difference between Windows and Linux: «15,625 limit» exists in Windows only.

Anyway, I use (time) very often, so it would be really useful for me to know, how (time) function works on small intervals.

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Re: (time) function: big and small intervals

Post by cormullion »

You can sometimes get more detail from now. On MacOS X:

Code: Select all

> (dotimes (x 10) (println ((now) 6)))
339887
339934
339998
340048
340059
340162
340170
340228
340242
340250
340250
but it's platform-dependent I think.

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: (time) function: big and small intervals

Post by Lutz »

Currently on Windows the resolution of 'sleep' and 'time' is dependent on the OS system clock working with a resolution of 10ms to 25ms depending on the hardware Windows is running on. On UNIX systems the resolution is in the microseconds range and on many UNIX systems the 'sleep' time is internally measured in the order or nano seconds.

Internally 'time' measures in micro seconds order on all OS and an overflow happens when 35 minutes (about 0x7fffffff microseconds) are reached. The display you see is an artifact of a 32-bit integer overflow and a transformation into a floating point number returned by 'time'. In a future version this will be extended to 0x7fffffff * 1000000 seconds which is approximately 68 years of maximum 'time' value.

Fritz
Posts: 66
Joined: Sun Sep 27, 2009 12:08 am
Location: Russia

Re: (time) function: big and small intervals

Post by Fritz »

Aha, I see now. I will span now intervals from 50ms and longer in Windows. 68 years should be enough for me too :)

Locked