Few things II

Walter Bright newshound1 at digitalmars.com
Tue Aug 7 11:15:53 PDT 2007


bearophile wrote:
> 13) The Haskell language community is quite organized, they have a large page on the main Haskell site that compares the best ways to create the entries for the Shootout site. They have even improved the language because one of such tests has shown a bad (slow) side of Haskell. I have recently posted few D entries into the Shootout site, with mixed results (one entry is at the top).
> Regarding the shootout code the following code may be used by DMD developers to improve the compiler, it shows a bad side of DMD compared to GCC:
> 
> C code:
> 
> #include <stdio.h>
> #include <stdlib.h>
> unsigned long fib(unsigned long n) {
>     return( (n < 2) ? 1 : (fib(n-2) + fib(n-1)) );
> }
> int main(int argc, char *argv[]) {
>     int N = ((argc == 2) ? atoi(argv[1]) : 1);
>     printf("%ld\n", fib(N));
>     return(0);
> }
> 
> 
> The D code:
> 
> import std.stdio, std.conv;
> ulong fib(ulong n) {
>     return (n < 2) ? 1 : (fib(n-2) + fib(n-1));
> }
> void main(string[] argv) {
>     ulong n = ((argv.length == 2) ? toUlong(argv[1]) : 1);
>     writefln(fib(n));
> }
> 
> 
> Used:
> gcc version 3.4.2 (mingw-special)
> DMD Digital Mars D Compiler v1.020 (Windows)
> 
> Compiled with:
> gcc -O2 fiboC.c -o fiboC.exe
> dmd -O -release -inline fiboD.d
> 
> Timings with n = 38:
> C: 4.38 s
> D: 5.28 s
> 
> I think such diffece is big enough to justify an improvement.

D's ulong is 64 bits, while C's unsigned long is 32 bits. This is likely 
the source of the speed difference.



More information about the Digitalmars-d mailing list