Path: utzoo!attcan!uunet!auspex!guy From: guy@auspex.auspex.com (Guy Harris) Newsgroups: comp.unix.programmer Subject: Re: How to measure cpu time to ~ 1 millisecond? Keywords: time Message-ID: <4112@auspex.auspex.com> Date: 29 Sep 90 22:22:07 GMT References: <237@locke.water.ca.gov> <3819@aix.aix.kingston.ibm.com> Organization: Auspex Systems, Santa Clara Lines: 27 >>Setup: Sun 4/330, SunOS 4.1 >> >>We need to measure cpu time in a program down to about a 1 millisecond >>resolution. The clock call says it can only measure to 16.7 ms. Any >>other ideas on how cpu time can be measured? > >My best guess here is that your machine runs at 60 clock ticks per second. Actually, it's 100 clock ticks per second. The reason why "clock()" says it acts as if it were 60 clock ticks per second is that the code was taken straight from S5, which uses the "times()" call, which in SunOS maps the internal CPU time values to values that look as if they were in 1/60ths of a second (this is inherited from 4.2BSD, which did this for binary compatibility with 4.1BSD). >Your system might, however, provide a getrusage() system call (resource.h). It does, but... >If you have it, that gives the "best estimation" for your system of CPU >utilization (system and user modes) with a granularity of microseconds >(see struct timeval in time.h) ...just because a "struct timeval" has a "tv_usec" field doesn't mean it has a one-microsecond resolution. The actual resolution is still the underlying resolution of whatever clock is used, and on a 4/330 that's the rate at which clock interrupts are generated, or 100 per second.