How long does a procedure call, library call and system call take on
your favorite machine and operating system combination ?
On your favorite computer(s) and operating system(s), measure the
following latencies. Since many of these latencies are below the resolution
of a typical clock, you will want to read the system clock, perform
the operation in question many (100s to 100000s of times), read the
clock again, subtract and divide.
- A function call within the application (e.g. main() calls a(), on any platform).
- A library call that does not require kernel involvement (e.g.
memset() with a length argument of 0 "{char foo[10]; memset(foo, 0, 0);}" on any platform).
- A system call that requires no service time from the kernel (e.g. a close() call with an invalid file descriptor "close(-1);" - make sure that on
your chosen platform, the call is propagated to the kernel instead of being
handled in a library wrapper without going to the kernel).
- Extra credit: measure the time to create a process or thread and
execute it (e.g. fork()/wait() in Unix, subclass java.lang.Thread and start()/join() time in Java, CreateThread()/SwitchToThread()/GetExitCodeThread() on Windows). The created thread should do no work, so you can measure the minimum
possible latency.
You can use gettimeofday() in Unix or GetSystemTime() in Windows to acquire a timestamp. This file provides a skeleton for
performing these measurements on Windows.
Turn in your code and the results of your measurements. Note the platform and OS on which you performed your timings (e.g. Pentium 4@2 GHz+Windows, or Pentium 4@2 GHz+Linux2.4.2).