[Solved] D-lang being faster than C++? [closed]


find() seems to be heavily used and they are very different in D and C++ implementations:

int find(int x) {
    return ds[x] = (x == ds[x] ? x: find(ds[x]));
}

vs:

long long find(long long node)
{
    if(parents[node] == node)return node;
    else return find(parents[node]);
}

find() in D modifies array (looks like some kind of dynamic programming, were you cash previous result) while in C++ you always do full lookup. You should compare apples to apples, especially this code could be written exactly the same way in C++.

1

solved D-lang being faster than C++? [closed]