On 19/11/11 4:34 AM, Alex Rønne Petersen wrote:
On 19-11-2011 04:07, bearophile wrote:
Do you know why an associative array like this:
uint[immutable(char)[]] aa;

Is almost two times faster than a very similar associative array like
this?
uint[immutable(E)[]] aa;

Where E is a named typed enum of chars like:
enum E : char { a='a', b='b', c='c', d='d', ... }

Testing code:
http://codepad.org/hzcRH8Bd

Bye,
bearophile

With an enum, I assume the hashes can be precomputed.

- Alex

Then shouldn't the enum be faster? :-)

alias immutable(char)[] MyString; // runtime 4.41 seconds
//alias immutable(E)[] MyString;  // runtime 7.92 seconds

My guess is that DMD has an optimised path for strings that isn't (but should be) used for char-typed enums.

Reply via email to