(time) function: big and small intervals

Started by Fritz, March 21, 2010, 03:13:44 PM

Previous topic - Next topic

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.


> (time (sleep 3600000))
1,844674407e+016


1,8e+016ms = 595 000 years, hehe.



2. Small intervals.


> (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

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


> (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

#2
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

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