kryglik [email protected] wrote:
Unserialized Hash is 1.5x faster in has_key? method. Tried it with
Well, insertion order will be same, won’t be?
Not necessarily. If Marshal.dump uses the current order in the hash for
writing then the insertion order during loading is likely to be
from the original insertion order.
puts "loading hash"
t2 = Time.now
puts "hash: " + h.size.to_s
puts "hled: " + h_slovo.size.to_s
Your time measurement is far too unprecise on a modern system. You’ll
to repeat lookups to get more accurate results. I get a difference
and 10 percent with the attached code - regardless of GC enabled or
disabled. Strange though that the copy is always slower. This is an
Note, if you freeze keys lookups in the original hash are much faster
because then hash keys are not copied on insertion (an optimisation of
unfrozen Strings as hash keys), i.e., during lookup if the key is the
it’s also the same object which will be the first test - and of course
test is much faster than sequential comparison of characters.
Another note, a more realistic scenario would be if not 10% of all keys
used for lookup but if there also were keys that are not present in the