Ordinary single-threaded *nix programs can be benchmarked with utils like time
, i.e.:
# how long does `seq` take to count to 100,000,000
/usr/bin/time seq 100000000 > /dev/null
Outputs:
1.16user 0.06system 0:01.23elapsed 100%CPU (0avgtext+0avgdata 1944maxresident)k
0inputs+0outputs (0major+80minor)pagefaults 0swaps
...but numbers returned are always system dependent, which in a sense also measures the user's hardware.
Is there some non-relative benchmarking method or command-line util which would return approximately the same virtual timing numbers on any system, (or at least a reasonably large subset of systems)? Just like grep -m1 bogo /proc/cpuinfo
returns a roughly approximate but stable unit, such a benchmark should also return a somewhat similar unit of duration.
Suppose for benchmarking ordinary commands we have a magic util bogobench
(where "bogo" is an adjective signifying "a somewhat bogus status", but not necessarily having algorithms in common with BogoMIPs):
bogobench foo bar.data
And we run this on two physically separate systems:
- a 1996 Pentium II
- a 2015 Xeon
Desired output would be something like:
21 bogo-seconds
So bogobench
should return about the same number in both cases, even though it probably would finish in much less time on the 2nd system.
A hardware emulator like qemu
might be one approach, but not necessarily the only approach:
- Insert the code to benchmark into a wrapper script
bogo.sh
- Copy
bogo.sh
to a bootable Linux disk image bootimage.iso, within a directory wherebogo.sh
would autorun then promptly shutdown the emulator. During which it outputs some form of timing data to parse into bogo-seconds. Run bootimage.iso using one of
qemu
's more minimal-machine
options:qemu-system-i386 -machine type=isapc bootimage.iso
But I'm not sure how to make qemu
use a virtual clock, rather than the host CPU's clock, and qemu
itself seems like a heavy tool for a seemingly simple task. (Really MAME or MESS would be more versatile emulators than qemu
for such a task -- but I'm not adept with MAME, although MAME currently has some capacity for 80486 PC emulation.)
Online we sometimes compare and contrast timing-based benchmarks made on machine X with one made on machine Y. Whereas I'd like both user X and Y to be able to do their benchmark on a virtual machine Z, with bonus points for emulating X or Y (like MAME) if need be, except with no consideration of X or Y's real run-time, (unlike MAME where emulations are often playable). In this way users could report how programs perform in interesting cases without the programmer having to worry that the results were biased by idiosyncrasies of a user's hardware, such as CPU quirks, background processes hogging resources, etc.
Indeed, even on the user's own hardware, a time
based benchmark can be unreliable, as often the user can't be sure some background process, (or bug, or hardware error like a bad sector, or virus), might not be degrading some aspect of performance. Whereas a more virtual benchmark ought to be less susceptible to such influences.