Language execution speeds or "The Fibonacci Stats"

Hey Stefan,

following our discussion last week, I thought it'd be useful to have at least a
light comparison of different scripting/programming languages available. Just to
put decisions against Guile, for Python or for Javascript (or C++ at the BSE
core) into perspective performance wise.

I've implemented a small program to print fibonacci(40) in various languages,
the stupid recursive variant of course. It's simple enough that the needed bits
are covered next to "Hello World" for most languages, and complex enough that
the compilers won't optimize it away and VMs are significantly pressured during
execution. For reference, here's how it looks in Python:
        def f (n):
          if n > 1:     return f (n - 2) + f (n - 1)
          if n == 1:    return 1
          else:         return 0
        print (f (40))

Execution times are measured with bash's "time", here's the ranking:

// user 0m0.328s        (gcc -O6)
// user 0m0.636s        (Java SE 8)
// user 0m0.716s        (clang -O3)
// user 0m0.720s        (rust)
// user 0m0.884s        (D - gdc-5.4.0)
// user 0m1.596s        (js - node v4.2.6, v8
#  user 0m10.168s       (jruby)
// user 0m14.904s       (php7)
#  user 0m17.556s       (ruby 2.3.1p112)
-- user 0m22.480s       (lua)
// user 0m24.964s       (Java SE 8, interpreted mode execution only)
// user 0m26.152s       (pike)
#  user 0m27.292s       (jython)
#  user 0m38.288s       (python2)
#  user 0m41.260s       (python3)
#  user 0m57.584s       (awk)
;; user 1m4.724s        (guile)
#  user 1m39.080s       (perl5)
#  user 9m5.000s        (perl6 - Rakudo 2016.06)

A couple interesting observations can be made:

- The statically typed languages are definitely fastest and all of them use

- Java still beats the C implementation compiled by clang and that includes the
time needed by OpenJDK to JIT the function, impressive! Though I wonder if the
JIT here's clever enough to make some consexpr optimizations behind the scenes,
I have a hard time seeing how it can beat clang otherwise...

- Thoguh the statically typed compiled languages are generally faster by an
order of magnitude, Javascript is fairly close. Impressive!

- So Javascript as provided by V8 is by far the fastest dynamically typed
execution environment.

- It's interesting to note that jruby and jpython both significantly outperform
their C implementations, i.e. benefit from using the JVM.

- I would have hoped that python3 improved over python2, but didn't... ;-(

- Using Guile as a scripting language is a particularly bad choice for
computation performance. I really would have thought Guile beats the pants off
of Python and Ruby, and probably be up there with PHP.

- The PHP7 speed is impressive, given that it's dynamically typed and *not*
JITed (just like Guile). Btw, PHP7 supports typehints so we can add 'int' to the
function arguments, but that actually makes it run *slower*, b/c there's not JIT
here that can take advantage of the hints. It runs in 0m18.766s with typehints

- Perl6 is just... off limits. Allmost makes me wonder if it even makes sense to
pursue that language implementation.

PS: The language selection was done mostly by reading the Wikipedia language
lists and picking the ones that I vaguely knew and have access to on Ubuntu.
Fell free to provide ports to anything you think is missing. ;-)

Yours sincerely,
Tim Janik
Free software author.

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]