D and Nim

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Sun Jan 4 16:01:06 PST 2015


On 1/4/2015 1:46 PM, Ary Borenszweig wrote:
> There are examples of D code in these two repos:
>
> https://github.com/logicchains/LPATHBench
> https://github.com/kostya/benchmarks
>
> Nim is faster than D. And it does so with much less code.

You could write the D version with about the same lines of code as the Nim 
version. For example, the D version has two implementations in it, the Nim one. 
The D version has an extra function it in that is manually inlined in the Nim one.

The only significant difference is that Nim doesn't use { }, and so saves a line 
here and there.

For another example,

Nim:

    for neighbour in nodes[nodeId].neighbours:

D:

    foreach(immutable route neighbour; nodes[nodeID].neighbours){

Correctly written D:

     foreach (neighbour; nodes[nodeID].neighbours){

Not a dime's worth of difference. For another,

Nim:

     echo result, " LANGUAGE Nim ", int(duration * 1000)

D:
     printf("%d LANGUAGE D %d\n", len, sw.peek().msecs);

Correctly written D:

     writeln(len, " LANGUAGE D ", sw.peek().msecs);

Pretty much the same for the rest.




More information about the Digitalmars-d mailing list