Simple integer math benchmark

new topic     » topic index » view thread      » older message » newer message

I know I'm preaching to the choir as it were here, but you might be interested in a little benchmarking I did recently.

I tested the following simple/naive/stupid prime number generator with a number of interpreters, and Euphoria came out looking very nice.

integer n, lim, k, p, pc 
 
pc  = 0 
n   = 1 
lim = 5000000 
 
while n < lim do 
    k = 3 
    p = 1 
    n = n + 2 
    while k * k <= n and p do 
        p = floor(n / k) * k != n 
        k = k + 2 
    end while 
    if p then 
        pc = pc + 1 
    end if 
end while 
? pc 

I adapted the above code to a number of interpreters, and here are the results:

prime.c         1.00 seconds - test program, compiled with gcc -O3 
Euphoria        8.27 seconds - openeuphoria.com 
gforth          8.56 seconds - complang.tuwien.ac.at/forth/gforth 
tinypas.c      15.82 seconds - 
tiny-c.c       17.10 seconds - iro.umontreal.ca/~felipe/IFT2030-Automne2002/Complements/tinyc.c 
toy2.c         17.64 seconds - QDepartment/Files/Ed-Davis-stuff/toy.c 
Pike           30.43 seconds - pike.lysator.liu.se 
jwillia basic  50.26 seconds - github.com/jwillia3/BASIC 
oc             66.44 seconds - exmortis.narod.ru/pcode_src/oc.zip 
atlast         77.08 seconds - fourmilab.ch/atlast 
NaaLaa         92.98 seconds - naalaa.com 
Lua           109.56 seconds - lua.org 
Perl          137.69 seconds - perl.org 
si            189.23 seconds - drdobbs.com/cpp/si-a-c-like-script-interpreter/184408141 
Yabasic       203.94 seconds - yabasic.de 
cint          217.31 seconds - root.cern.ch/drupal/content/cint 
Python        225.83 seconds - python.org 
Ruby          242.52 seconds - ruby-lang.org 
ch            294.08 seconds - softintegration.com 
LB Booster    533.65 seconds - bbcbasic.co.uk/lbb 
Little C      767.34 seconds - books.mcgraw-hill.com/downloads/products/0072121246/0072121246_code.zip 
PicoC         795.76 seconds - code.google.com/p/picoc 

Of course you can write a faster primer number generator, but that wasn't the goal. The goal was to get a (perhaps weak) sense of interpreter speed, compared to C, and a simple interpreter I'd written, regarding integer operations and looping.

  1. prime.c - Test program compiled with gcc -O3
  2. Euphoria - It rocks!
  3. gforth - Fast Forth interpreter
  4. tinypas.c - C translation of Jan van de Snepscheut's Pascal S. Compiles to a VM. The compiler does some simple peephole optimization.
  5. tiny-c - Marc Feeley's Tiny C. This is a tiny C subset VM compiler/interpreter. Modified to add the operators needed to run the benchmark.
  6. toy2.c - Slightly modified version of toy.c. The one listed at QDepartment takes 51.01 seconds.
  7. Pike - Neat C-like scripting language.
  8. jwillia basic- A really cool BASIC interpreter, all in one header file! Compiles to a VM.
  9. oc - A tiny C subset VM compiler/interpreter. Was as 1991 OCCC Winner. The unobfuscated version is actually quite readable.
  10. atlast - Forth interpreter
  11. NaaLaa - Cool language for making games.
  12. Lua - Popular scripting language.
  13. Perl - There is always more than one way to do it...
  14. si - A tiny C subset interpreter by Al Stevens, circa 1989. This is almost a pure interpreter, however it does tokenize the source before interpreting it.
  15. Yabasic - Nice basic interpreter - sadly, no longer developed as of 2013.
  16. cint - Full C interpreter.
  17. Python - Popular scripting language.
  18. Ruby - Popular scripting language.
  19. ch - Full C interpreter.
  20. LB Booster - Runs Liberty BASIC programs faster than Liberty BASIC.
  21. Little C - Herbert Schildt's - pure (infamous?) tiny C subset interpreter.
  22. PicoC - Large subset of C interpreter.

I actually did not realize that Euphoria was so fast and/or set out to show the same. I was testing the speed of a simple interpreter I'd written, and I wanted to see how it stacked up against a few other interpreters.

And finally, like all benchmarks, take this one with a grain of salt smile

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu