benchmark.m

Francesco Potorti` <[email protected]> Tue, 15 Nov 2005 05:52:03 -0600
Newsgroups gmane.comp.gnu.octave.sources
Organization ISTI-CNR, via Moruzzi 1, I-56124 Pisa, +39-0503153058
Message-ID <[email protected]>
This is a slightly revisited version of my very old benchmark.m, which I
had discontinued due to the difficulties of obtaining consistent results
from different machines due to possible compilation differences.

In the meantime, this problem has grown, so the original purpose of
providing a list of hardware box performance is even more out of scope.
Anyway, the benchmark can be still useful for providing a quick
comparison between different boxes or compilation options.  So here it
is again. =20

The reference machine has changed from the ancient Sun Sparc 10/40 to an
old Pentium II 350 MHz which is about 400 times faster on small matrix
inversion and fft (due to the cache size, I suppose), only 3 times
faster on LSODE and only 4 times faster on loop performance.  I have
grown the matrix size to account for modern cache sizes.

For the retrocomputing interested, the old machine comparison is at
 <ftp://fly.isti.cnr.it/pub/software/octave/bm_results>.=20

Enjoy.


=3D=3D=3DFile ~ftp/pub/software/octave/benchmark.m=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D
bm_version =3D ["bm ", "2.2"];

# Benchmark for octave, released under the GNU GPL, version 2 or later
# Francesco Potort=81=81=EC <[email protected]>  1996, 1997, 2005
# 2005/11/15 11:35:36
#
# latest version at <ftp://fly.isti/pub/software/octave/benchmark.m>
# old results list at <ftp://fly.isti.cnr.it/pub/software/octave/bm_resul=
ts>

printf ("Octave benchmark version %s\n", bm_version);

# To add reference times for your machine run the benchmark and
# add the values contained in the bm_mytime vector.
#
bm_refname =3D "Pentium II 350 MHz";
bm_reftime =3D [1.77 1.38 .857 .778 1.12];


# Use clock() if cputime() does not work on this particular port of octav=
e.
# In this case, time will be computed on a wall clock, and will make sens=
e
# only on a machine where no other processes are consuming significant cp=
u
# time while the benchmark is running.
global bm_uses_cputime =3D (cputime() !=3D 0);
if (!bm_uses_cputime)
  disp ...
    ("WARNING: if other processes are running the figures will be inaccur=
ate");
endif
function t =3D bm_start ()
  global bm_uses_cputime
  if (bm_uses_cputime)
    t =3D cputime();
  else
    t  =3D clock();
  endif
endfunction
function et =3D bm_stop (t);
  global bm_uses_cputime
  if (bm_uses_cputime)
    et =3D cputime()-t;
  else
    et =3D etime(clock(),t);
  endif
endfunction

# Used for the lsode test.
clear xdot
function xdot =3D xdot (x, t)
  r =3D 0.25; k =3D 1.4; a =3D 1.5; b =3D 0.16; c =3D 0.9; d =3D 0.8;
  xdot(1) =3D r*x(1)*(1 - x(1)/k) - a*x(1)*x(2)/(1 + b*x(1));
  xdot(2) =3D c*a*x(1)*x(2)/(1 + b*x(1)) - d*x(2);
endfunction

#
# Do benchmark
#
function [name, time] =3D bm_test(f,rep)		# Actual test functions
  global t;
  start =3D bm_start();
  for i =3D 1:rep
    if     (f=3D=3D1) name=3D"Matrix inversion (LAPACK)";
                  bm_x=3Dinv(hadamard(512));
    elseif (f=3D=3D2) name=3D"Schur decomposition (LAPACK)";
                  bm_x=3Dschur(hadamard(256));
    elseif (f=3D=3D3) name=3D"Differential equation (LSODE)";
                  bm_x=3Dlsode("xdot",[1;2],(t=3Dlinspace(0,50,400)'));
    elseif (f=3D=3D4) name=3D"Fourier transforms (FFTPACK)";
                  bm_x=3Difft2(fft2(hadamard(512)));
    elseif (f=3D=3D5) name=3D"for loop";
                  for i=3D1:20000;bm_x=3Di^2;endfor
    endif
  endfor
  time =3D bm_stop(start)/rep;
endfunction

bm_targetaccuracy =3D 0.025;		# target accuracy of mean of times
bm_minrepetitions =3D 7;			# min number of repetitions per test
bm_maxtime =3D 60;			# max runtime per test [seconds]
bm_mintime =3D 0.3;			# min runtime per test [seconds]
bm_runtime =3D 3;				# target runtime per test [seconds]

printf ("Speed of octave %s on %s\n...
  %s has score 1.0, higher numbers are better\n", ...
        version(), computer(), bm_refname); fflush(stdout);
bm_mytime =3D zeros(size(bm_reftime));
for f =3D 1:length(bm_reftime)
  res =3D [];
  bm_test(f,1);				# increase the RSS, load things
  rep =3D 1;				# number of repetitions per run
  while (1)				# we would need a do..while really
    [name,time] =3D bm_test(f,rep);	# evaluate name and time
    if (time*rep > bm_mintime)		# run for at least bm_mintime
      break;				# found approximate time
    endif
    rep =3D 2*rep;			# approaching min run time
  endwhile
  printf("%-33s", name); fflush(stdout);# print name
  rep =3D round(bm_runtime/time);		# no. of repetitions per run
  rep =3D max(1,rep);			# slow machines need this
  for runs =3D 1:bm_maxtime/bm_runtime	# do runs
    [name,time] =3D bm_test(f,rep);	# run
    res(runs) =3D bm_reftime(f)/time;	# store relative performance
    if (runs < bm_minrepetitions)	# jump rest of for loop
      continue
    endif
    res =3D sort(res);
    bm_mean =3D mean(res(2:runs-1));	# remove min and max results
    if (std(res)/bm_mean < bm_targetaccuracy)
      break
    endif
  endfor				# end of repetitions loop
  bm_mytime(f) =3D bm_reftime(f)/bm_mean;
  # print 95% confidence interval
  printf("%5.2f +/- %.1f%% (%d runs)\n", ...
         bm_mean, 200*std(res)/bm_mean, runs*rep); fflush(stdout);
endfor
clear bm_x
# Display the geometric mean of the results
printf("-- Performance index (%s): %.2g\n\n", bm_version, ...
       prod(bm_reftime./bm_mytime)^(1/length(bm_reftime)));
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

--=20
Francesco Potort=81=81=EC (ricercatore)        Voice: +39 050 315 3058 (o=
p.2111)
ISTI - Area della ricerca CNR          Fax:   +39 050 313 8091
via G. Moruzzi 1, I-56124 Pisa         Email: [email protected]
Web: http://fly.isti.cnr.it/           Key:   fly.isti.cnr.it/public.key