Using the CPU timer
Introduction
It is possible to use the native JVM profiling API to obtain more
accurate times from JBench. The granularity isn't usually affected
(eg on Windows 2000 the granularity is still 10ms) but the actual
CPU time spent executing code in the main JBench thread is reported,
rather than the "wall-clock" time which is affected by how heavily
loaded your computer is. I am indebted to JavaWorld and in
particular the
Java Tip 92 article for the basis of the code used.
Installing the native library
This interface requires a native library, which must be installed.
The source for the library and pre-built binaries for Linux (i386),
Solaris (sparc) and Windows are provided in the native
directory of both the source and binary distributions of JBench.
Generally, under Windows you should place cputimer.dll
in your jre/bin
directory, under Linux you should place
libcputimer.so
in your java/lib/i386
directory, and under Solaris you should place
libcputimer.so
in your java/lib/sparc
directory. Different JVMs may differ in how they pick up native
libraries, however, so consult your JVM documentation when in doubt.
Configuring JBench to use the CPU timer
In your JBench configuration file, set jbench.timer=cpu
to use the native library. If you're running on Linux and see
absurdly small times being reported, also set
jbench.timer.scale=1000
- as far as I can see, there's
a bug in some HotSpot JVMPI implementations which give values in
microseconds instead of nanoseconds.
Running JBench with the native library
On the command line, you should use -Xruncputimer
as a command line option to the VM, eg:
java -Xruncputimer -jar JBench.jar jbench.properties
This will initialise the library properly before it is used.
JBench Manual