D
I've to say, D is very interesting language with several unique features. What about performance? How it compares to VM-based languages?
It took 3.6 seconds in debug mode and 1.3 seconds in release mode, which is on pair with F#.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
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