Skip to content

Instantly share code, notes, and snippets.

@ksss
Last active August 29, 2015 13:58
Show Gist options
  • Save ksss/10088148 to your computer and use it in GitHub Desktop.
Save ksss/10088148 to your computer and use it in GitHub Desktop.
$ ./bin/mruby hash_symbol_key.rb
set * 100 : 0.35799999999999
get * 100 : 0.11299999999999
update * 100 : 0.12799999999999
set * 1000 : 6.31099999999999
get * 1000 : 2.2480
update * 1000 : 2.4580
set * 10000 : 387.5570
get * 10000 : 184.548999999999
update * 10000 : 186.326999999999
$ ./bin/mruby hash_symbol_key.rb
set * 100 : 0.0850
get * 100 : 0.04199999999999
update * 100 : 0.06499999999999
set * 1000 : 1.18399999999999
get * 1000 : 0.56999999999999
update * 1000 : 0.75099999999999
set * 10000 : 10.9529999999999
get * 10000 : 4.01699999999999
update * 10000 : 6.46199999999999
# ignore initialize time
Time.now
[100,1000,10000].each do |n|
h = {}
i = 0
t = Time.now
while i < n
h[i.to_s.to_sym] = i
i += 1
end
puts "set * #{n} : #{(Time.now - t) * 1000}"
i = 0
t = Time.now
while i < n
dummy = h[i.to_s.to_sym]
i += 1
end
puts "get * #{n} : #{(Time.now - t) * 1000}"
i = 0
t = Time.now
while i < n
h[i.to_s.to_sym] = -i
i += 1
end
puts "update * #{n} : #{(Time.now - t) * 1000}"
end
$ ruby hash_symbol_key.rb
set * 100 : 0.203
get * 100 : 0.033
update * 100 : 0.041
set * 1000 : 1.574
get * 1000 : 0.398
update * 1000 : 0.47600000000000003
set * 10000 : 15.363
get * 10000 : 5.1209999999999996
update * 10000 : 5.564
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment