D

I've to say, D is very interesting language with several unique features. What about performance? How it compares to VM-based languages?

import std.stdio;
import std.datetime;
void time(void function() f) {
auto sw = StopWatch(AutoStart.yes);
f();
sw.stop();
writefln("%s ms elapsed.", sw.peek.msecs);
}
pure nothrow T fib(T)(T n)
{
if (n < 2) return n;
return fib(n - 1) + fib(n - 2);
}
void main(string[] args)
{
time(function() {
for(auto n = 0; n < 40; ++n) {
auto res = fib(n);
writefln("fib(%d) = %d", n, res);
}
});
stdin.readln();
}
view raw fib.d hosted with ❤ by GitHub


It took 3.6 seconds in debug mode and 1.3 seconds in release mode, which is on pair with F#.


  • C# - 1.26
  • D (DMD) - 1.3
  • F# - 1.38
  • Nemerle - 1.45
  • Haskell - 2.8
  • Clojure - 9
  • Erlang - 17
  • Ruby - 60
  • Python - 120

Comments

Popular posts from this blog

Regular expressions: Rust vs F# vs Scala

Hash maps: Rust, F#, D, Go, Scala

Haskell: performance