A tool is provided for measuring code/time requirements for arbitrary code fragments. This is kept in the ‘perf’ directory and is not built by default. If you wish to use this tool use the following targets:
% cd perf % make perf
The output is ‘perf.tex’, ‘perf.dvi’ and ‘perf/index.html’.
Note that the measurement requires the following:
As an indication of the values you can expect here is part of the results for ‘make perf’ on a 200Mhz Cyrix MMX (i386) chip which runs at about 200 BogoMips under FreeBSD 2.2.6 with ‘-O’.
‘assert(i >= 2);’ 28 bytes, 19ns.
‘TRAD_assert(i >= 2);’ 47 bytes, 20ns.1
‘I(i >= 2);’ 9 bytes, 18ns.
‘DI(i >= 2);’ 1 byte, 147.4us.
‘I(A(int i=0, i!=10, i++, a[i]>=0));’ 28 bytes, 287ns.
‘d = now();’ 8 bytes, 3.1us.
‘printf("helloworld\n");’ 13 bytes, 9.1us.
‘L("helloworld\n");’ 18 bytes, 8.9us.
‘DL("helloworld\n");’ 1 byte, 26.4us.
Note that these measurements were on a system that was configured with ‘I_DEFAULT=fast ./configure’. The default output of ‘./configure’ produces nice error messages at the cost of increased code space.
[1] This is the traditional assert which uses ‘fprintf’ and ‘exit’ in a macro. The BSD ‘assert’ macro used in FreeBSD is a bit smarter and calls a function to do the message printing and exiting. Note that the real cost of this function is even higher since we are only measuring the code space requirements, not the space required for the message strings.