Other Languages


Unix Bench Calculator (bc)

/* Ahl's simple benchmark - the bc version */

s=0
scale=20

define r(x) {
  auto a,b
  a=scale
  scale=0
  s=s*214014+40643 
  s=s+((s/65536)%65536)
  s=s%429496729
  b=(s%65536)
  scale=a
  return(x*b/65536)
}

define a(x) {
  if (x>=0) return(x)
  return(-x)
}

define m(x) {
  auto i,n,e,t,r,u
  "ahl.bc -- The bench calculator version of Ahl's simple benchmark
"
  for (e=0;e<x;e++) {
    r=0 
    u=0
    for (n=1;n<=100;n++) {
      a = n
      for (i=1;i<=10;i++) {
        a = sqrt(a) 
        r = r + r(1.0)
      }
      for (i=1;i<=10;i++) {
        a = a*a 
        r = r + r(1.0)
      }
      u = u + a
    }
  } 
  "iterations="
  e
  "Accuracy="
  a(1010.0-u/5.0)
  "Random="
  return(a(1000.0-r));
}

m(2)
quit


Unix Desk Calculator (dc)

Warning, this contains control charaters represented by underlined characters preceeded by a carat.

0ss
20k

[0Si0SaSxKsa 0k 10lx* 10/silakliLxs.Las.Lis. 1QLxs.Las.Lis.0 1Q]s       

[Sxlxl  xssLxs.0 1Q]s^S

[0Sb0SaSxKsa 0kls 214014* 40643+sslsls 65536/ 65536%+ssls 429496729%ssls 65536%s
blaklxlb* 65536/Lxs.Las.Lbs. 1QLxs.Las.Lbs.0 1Q]s^R

[lxLxs. 2Q]s0
[Sxlx 0!>0  0lx-Lxs. 1QLxs.0 1Q]s^A

[lavsalr 1.0l^Rx+srlid1+sis.li 10!<3]s3
[lala*salr 1.0l^Rx+srlid1+sis.li 10!<4]s4
[lnsa 1dsis.li 10!<3  1dsis.li 10!<4 lula+sulnd1+sns.ln 100!<2]s2
[ 0sr 0su 1dsns.ln 100!<2 led1+ses.lelx>1]s1
[0Su0Sr0St0Se0Sn0SiSx[ahl.dc -- The desk calculator version of Ahl's simple benchmark
]P 0dses.lelx>1 [iterations=]Pleps.[Accuracy=]P 1010.0lu 5.0/-l^Axps.[Random=]P 
1000.0lr-l^AxLxs.Lis.Lns.Les.Lts.Lrs.Lus. 1QLxs.Lis.Lns.Les.Lts.Lrs.Lus.0 1Q]s

2l^Mxps.
q


MAGIC/L (Sun 680X0 version)


; Ahl's simple benchmark 

long seed

make '?gettimeofday ucall 116. 2

define time long
  local long tv ( 2 )
  local long tz ( 2 )
  time := 0l
  ?gettimeofday ( tv , tz )
  time := tv ( 0 )
end

define random real 
  if ( seed == 0l ) 
    seed := time
  endif
  seed := ( seed * 214014l + 40643l ) 
  seed := seed xor lurshift ( seed , 16 ) 
  random := lfloat ( seed and 65535l ) / 65535.0
end
    
define ahl 
  local real r , s , a 
  local integer iterns 
  local long t 

  print "ahl.mg -- The MAGIC/L version of Ahl's simple benchmark"
  iterns := 0 
  r := 0.0
  s := 0.0
  t := time
  while ( t == time )
  repeat
  t := time 
  begin
    iterns := iterns + 1
    r := 0.0
    s := 0.0
    iter 100
      a := float ( i + 1 )
      iter 10 
        a := sqrt ( a )  
        r := r + random
      loop
      iter 10
        a := a * a 
        r := r + random
      loop
      s := s + a 
    loop
  until ( ( time - t ) >= 20l ) 
  t := time - t
  print iterns , " iterations"
  print lfloat ( t ) / float ( iterns ) , " seconds per iteration"
  print "Accuracy " , fabs ( 1010.0 - ( s / 5.0 ) )
  print "Random " , fabs ( 1000.0 - r )
end


IDL (Interactive Data Language)


pro ahl
  print,"ahl.pro - The IDL version of Ahl's simple benchmark"
  t=systime(1)
  repeat iter=0 until (t ne systime(1)) 
  t=systime(1)
  repeat begin
    iter=iter+1
    a=dindgen(100)+1
    for i = 1,10 do a=a^0.5
    r=total(randomu(seed,1000))
    for i = 1,10 do a=a^2
    r=r+total(randomu(seed,1000))
    s=total(a)
  endrep until ((systime(1)-T) ge 19.9999999)
  print,iter," iterations."
  print,20.0/iter," seconds per iteration"
  print,"accuracy ",abs(1010.-s/5.)
  print,"random ",abs(1000.-r)
end

Postscript

Submitted by Daniel Spangberg.
%!PS-Adobe-3.0
%%DocumentFonts: Helvetica
%%Title: Ahl's simple benchmark
%%Creator: Daniel Spangberg
%%BoundingBox:    56    78   539   763
%%EndComments 

% Random number between 0 and 1:
/random { rand 2147483647 div } def

% Number of iterations as parameter
/ahl {
  dup
  1 1 3 -1 roll {
     /r 0 def
     /s 0 def
     1 1 100 {
       /a exch def
       1 1 10 {
         a sqrt /a exch def
         random r add /r exch def
         pop % Remove loop index
       } for  
       1 1 10 {
         a dup mul /a exch def
         random r add /r exch def
         pop % Remove loop index
       } for  
       a s add /s exch def     
     } for
     pop % Remove loop index
  } for
  /Helvetica findfont 18 scalefont setfont
  /mystr 40 string def
  100 700 moveto (ahl.ps -- The Postscript version of Ahl's simple benchmark) show
  100 650 moveto (Iterations:) show
  200 650 moveto mystr cvs show
  100 600 moveto (Accuracy:) show
  200 600 moveto 1010 s 5 div sub abs mystr cvs show
  100 550 moveto (Random:) show
  200 550 moveto 1000 r sub abs mystr cvs show
  showpage
} def

%%EndProlog

% Random seed:
1 srand

% 10 iterations of benchmark:
10 ahl

%%Trailer

Yorick


/* Ahl's simple benchmark */
func ahl
{
  iter=0
  write,"ahl.i - The Yorick version of Ahl's simple benchmark"
  random_seed
  elapsed=array(double,3)
  timer,elapsed
  t=elapsed(0)
  do {
    timer,elapsed
  } while (elapsed(0)==t);
  start=elapsed(0);
  do {
    iter++
    a=double(indgen(100))
    for (i = 0;i<10;i++) a=a^0.5
    r=sum(random(1000))
    for (i = 0;i<10;i++) a=a^2
    r=r+sum(random(1000))
    s=sum(a)
    timer,elapsed
  } while ((elapsed(0)-t) <= 20.0)
  write,iter," iterations."
  write,20.0/iter," seconds per iteration"
  write,"accuracy ",abs(1010.-s/5.)
  write,"random ",abs(1000.-r)
}


Copyright © 2001 Eric Korpela
korpela@ssl.berkeley.edu