Created
August 30, 2012 23:04
-
-
Save jnicklas/3544217 to your computer and use it in GitHub Desktop.
Revisions
-
jnicklas revised this gist
Aug 30, 2012 . 2 changed files with 10 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,3 @@ require "benchmark" string_hash = {} @@ -9,11 +8,12 @@ symbol_hash[:"key_#{i}"] = i end string_accessors = Array.new(100000) { "key_#{rand(50000)}" } symbol_accessors = Array.new(100000) { :"key_#{rand(50000)}" } Benchmark.bm do |x| x.report("strings") { string_accessors.each { |a| string_hash[a] } } x.report("symbols") { symbol_accessors.each { |a| symbol_hash[a] } } x.report("strings, set") { string_accessors.each { |a| string_hash[a] = a } } x.report("symbols, set") { symbol_accessors.each { |a| symbol_hash[a] = a } } end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ user system total real strings 0.030000 0.000000 0.030000 ( 0.031394) symbols 0.010000 0.000000 0.010000 ( 0.019276) strings, set 0.040000 0.000000 0.040000 ( 0.036649) symbols, set 0.030000 0.000000 0.030000 ( 0.024406) -
jnicklas created this gist
Aug 30, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ require "benchmark" string_hash = {} symbol_hash = {} (0..50000).map do |i| string_hash["key_#{i}"] = i symbol_hash[:"key_#{i}"] = i end accessors = Array.new(100000) { rand(50000) } Benchmark.bm do |x| x.report("strings") { accessors.each { |a| string_hash[a] } } x.report("symbols") { accessors.each { |a| symbol_hash[a] } } x.report("strings, set") { accessors.each { |a| string_hash[a] = a } } x.report("symbols, set") { accessors.each { |a| symbol_hash[a] = a } } end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ user system total real strings 0.020000 0.000000 0.020000 ( 0.018910) symbols 0.020000 0.000000 0.020000 ( 0.018612) strings, set 0.030000 0.000000 0.030000 ( 0.029713) symbols, set 0.030000 0.000000 0.030000 ( 0.031306)