-
-
Save hassox/3544925 to your computer and use it in GitHub Desktop.
Revisions
-
Daniel Neighman revised this gist
Aug 30, 2012 . 2 changed files with 10 additions and 17 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,19 +1,12 @@ require "benchmark" hash = {'key' => 1, :key => 2} n = 5_000_000 Benchmark.bm do |x| x.report("strings") { n.times { hash['key'] } } x.report("symbols") { n.times { hash[:key] } } x.report("strings, set") { n.times { hash['key'] = 1 } } x.report("symbols, set") { n.times { hash[:key] = 1 } } 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 1.040000 0.010000 1.050000 ( 1.044701) symbols 0.460000 0.000000 0.460000 ( 0.461030) strings, set 1.250000 0.000000 1.250000 ( 1.253017) symbols, set 0.690000 0.000000 0.690000 ( 0.689607) -
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)