Pointless Fibonacci Benchmark #4253: Python vs. Simula
Pointless benchmarks of code generating Fibonacci numbers is a recurring theme on PRC, and in addition it’s also a place with frequent posts about esoteric programming languages.
So, today I thought I’d resurrect a programming language from my childhood years at the university. It was developed in the 1960s, and is considered one of the earliest object-oriented programming language. I speak of course of Simula.
So influential has this programming language been, that the creators of Simula, Ole-Johan Dahl and Kristen Nygaard, were awarded the IEEE John von Neumann Medal in 2001, as well as the 2001 A. M. Turing Award.
I’m not going to use anything like that in this example though, but I fully expect this post to singlehandedly resurrect Simula and position it alongside Erlang, Common Lisp, Haskell and OCaml. Now for some code…
BEGIN
INTEGER PROCEDURE fib(n); INTEGER n;
BEGIN
IF n = 0 OR n = 1 THEN
fib := n
ELSE
fib := fib(n-1) + fib(n-2)
END;
INTEGER i;
FOR i := 0 STEP 1 UNTIL 36 DO
BEGIN
OutInt(fib(i), 0);
OutImage;
END;
END;
Is this awesome, or what? This sure brings back a lot of memories. Simula is case insensitive, but common coding standards use upper case for keywords, a fact that Simula mode in Emacs kindly reminded me of when it uppercased keywords automatically. To compile this I used GNU Cim, which produces C code from Simula source files.
To have something to compare it with, I also wrote the same thing in Python. Here are the results from my crappy laptop:
vetler@quimby:~/crypt/devel/fib$ time python fib.py &>/dev/null real 0m41.838suser 0m41.835s sys 0m0.008s vetler@quimby:~/crypt/devel/fib$ time ./fib &>/dev/null real 0m25.693s user 0m25.646s sys 0m0.012s vetler@quimby:~/crypt/devel/fib$
Simula totally smokes Python away! ;)
Make love, not war!