How about a Hash template?
Andrej Mitrovic
andrej.mitrovich at gmail.com
Thu Apr 28 07:25:54 PDT 2011
You seem to be right. It looks like DMD is pretty good at optimizing
if statements. The Hash version is quite a bit slower actually.
Well, that's what happens when I assume things. :)
Here's a little benchmark of searching an array and hash of randomly
generated strings:
http://pastebin.com/GddUn3e3
On my system (in milliseconds):
Length: 128
Hash Foreach: 334
Array Foreach: 61
Hash Lookup: 6
Array Lookup: 31
I guess what I was really looking for is syntax sugar that expands this:
if (variable in value1, value2, value3, value4)
into this:
if (variable == value1 || variable == value2...)
or something of that sort. Otherwise my Hash/hash functions are pretty
useless. Sorry for not researching before opening the topic.
More information about the Digitalmars-d
mailing list