Benjamin Thaut:

If you replace the default hash function D uses with the MurMur hash function it brings it down even more to 8 seconds (29425713 ticks)

What compiler are you using? ldc2?

And is it a good idea to put MurMur in D?


50%  find free entry in hashmap
21%  parse uint

Perhaps the parse uint times can be improved. A lightly tested function to try:


uint toUint(const(char)[] txt) pure nothrow {
    auto p = txt.ptr;
    const q = p + txt.length;

    // Skip leading not-digits.
    while (p < q && (*p < '0' || *p > '9'))
        p++;

    uint result = 0;
    while (p < q && *p >= '0' && *p <= '9') {
        result = (result * 10) + (*p - '0');
        p++;
    }
    return result;
}

void main() {
    import std.stdio;
    "".toUint.writeln;
    "x".toUint.writeln;
    "-1".toUint.writeln;
    " 125 ".toUint.writeln;
    " 10000".toUint.writeln;
    " 1000000 ".toUint.writeln;
    " 10000000000000 ".toUint.writeln;
}


Its output (it's not a safe conversion):

0
0
1
125
10000
1000000
1316134912

Bye,
bearophile

Reply via email to