Reserving/Preallocating associative array?

Benjamin Thaut code at benjamin-thaut.de
Fri Dec 27 04:13:24 PST 2013


Am 27.12.2013 12:02, schrieb bearophile:
> 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?

dmd 2.064.2

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

I don't know about the properties of the MurMur hash function. I only 
know that it is cheaper to compute then the hash function D uses. To 
decide if it would be better then the currently choosen hash function, a 
in depth analysis would be required.

>
>
>> 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;
> }

The way I parse the uint already looks that way. I'm not using std.conv
https://github.com/Ingrater/thBase/blob/master/src/thBase/conv.d#L22

Kind Regards
Benjamin Thaut




More information about the Digitalmars-d mailing list