V
Volker Borchert
softwarepearls_com wrote:
|> Well, that the precise data inputs matter a lot (see benchmark code
|> below). For the test as written, the custom logic approach is roughly
|> twice as fast. But.. I saw that the length of input Strings matter a
|> lot, which is to be expected since the longer the Strings, the deeper
|> the if nesting gets. It's a race between HashSet's O(1) logic vs my
|> O(n) logc.
Only if the strings to test are re"used". The String.hashCode() takes
time proportional to String.length() the first time it is called for
any given String instance.
|> I also had a quick look at the generated bytecode (using Eclipse's
|> compiler, javac fans YMMV).. and found some recurring sillyness which
|> would not feature in the hand generated logic, so the custom approach
|> would give a significant performance advantage over HashSet.contains,
|> but only for really short Strings. Mine are about 3-5x longer than
|> those in the benchmark.. so for me, HashSet.contains() and String's
|> clever hashCode() wins.
The key might be code and data locality. How do the JIT compiled code
and the hashtable fit into instruction and data caches and vm pages?
BTW, have you tested switch against elsif?
|> Well, that the precise data inputs matter a lot (see benchmark code
|> below). For the test as written, the custom logic approach is roughly
|> twice as fast. But.. I saw that the length of input Strings matter a
|> lot, which is to be expected since the longer the Strings, the deeper
|> the if nesting gets. It's a race between HashSet's O(1) logic vs my
|> O(n) logc.
Only if the strings to test are re"used". The String.hashCode() takes
time proportional to String.length() the first time it is called for
any given String instance.
|> I also had a quick look at the generated bytecode (using Eclipse's
|> compiler, javac fans YMMV).. and found some recurring sillyness which
|> would not feature in the hand generated logic, so the custom approach
|> would give a significant performance advantage over HashSet.contains,
|> but only for really short Strings. Mine are about 3-5x longer than
|> those in the benchmark.. so for me, HashSet.contains() and String's
|> clever hashCode() wins.
The key might be code and data locality. How do the JIT compiled code
and the hashtable fit into instruction and data caches and vm pages?
BTW, have you tested switch against elsif?