| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Clock()Ing In My Sleep() |
Hi Jasen, JB>GW> Bit odd really, as the two compilers I've looked at so far say clock() JB>GW> measures time from program start. JB>It doesn't even do that. help-pc says it measures elapsed processor-time JB>for the process, so under an multitasking O/S it could well return a lower JB>value... (my turbo-c manual agrees) but clock under turbo-c 2.0 isn't JB>multitasker aware. I said as much in other posts in the thread... JB>After some experimentation under linux, it appears that a clock counts only JB>the time that the process is actually executing, in a program that does a JB>sleep(10) (10 seconds) clock returns 0 (no time elapsed) Yippee, a system that has it implemented correctly... JB>Two processes executing concurrently would share the "clocks" and would each JB>only see half the elapsed time. JB>This suggests that the (portable) sleep in snippets is broken in that it JB>doesn't stop clock(). And that uclock is broken in that it doesn't measure JB>cpu-time. I can't find a sleep() in SNIPPETS :-(. Which file? The routines in uclock.c don't claim to give processor run time, but absolute elapsed time to high resolution. They rely on direct access to the hardware tick generator, and so are only valid for PCs and only accurate under DOS. Under OS/2 the timer is virtualised and so not really accurate (it does say so in the comments at the top of the file). JB>I have no idea of what would happen under windows or OS/2 or on an Amiga or JB>Mac. It _should_ measure processor time. But what it actually does will depend almost as much on the compiler library routines as the OS... Watcom and IBM say it returns an approximation to processor time. Borland C/C++ 3.1 expects to be the only process running, and so returns system ticks since program start. Borland C/C++ for OS/2 1.0 says it returns processor time, but contradicts itself by saying "clock can be used to determine the time interval between two events.". I suspect they've got it wrong (what a suprise :-( ). [later] They have got it wrong :-(. No suprise there... I checked clock() under BCOS/2 V1.0, and it returns elapsed time, not processor time :-(. If you go to sleep() for 5 seconds, clock() shows 5 seconds time, rather than the 0 it should show if it measured processor time... George * SLMR 2.1a * Computers eliminate spare time. --- Maximus/2 3.01* Origin: DoNoR/2,Woking UK (44-1483-717905) (2:440/4) SEEN-BY: 396/1 622/419 632/371 633/260 267 270 371 634/397 635/506 728 SEEN-BY: 670/213 218 @PATH: 440/4 255/1 252/356 140/1 270/101 396/1 633/260 635/506 728 633/267 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.