aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-09 03:44:12 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-09 03:44:12 +0000
commit098b0ba572d624acdc2af1925db7feda4b72881e (patch)
treea0e2bed56264ea86dece8996b81bc969911a4296
parent3cb3966838601acf6490c30077f482dafe4db2d7 (diff)
downloadruby-098b0ba572d624acdc2af1925db7feda4b72881e.tar.gz
benchmark/bm_hash_aref_sym*.rb: force static symbols
Dynamic symbols hash more slowly because they need extra method dispatch in rb_any_hash. I am not sure if dynamic symbols are a realistic use case as hash keys, so this commit only restores performance when comparing against versions of Ruby which lack dsyms. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47854 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog4
-rw-r--r--benchmark/bm_hash_aref_sym.rb7
-rw-r--r--benchmark/bm_hash_aref_sym_long.rb7
3 files changed, 16 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 95ef500b2d..467be7fbb7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Thu Oct 9 12:40:28 2014 Eric Wong <e@80x24.org>
+
+ * benchmark/bm_hash_aref_sym*.rb: force static symbols
+
Thu Oct 9 12:38:28 2014 Eric Wong <e@80x24.org>
* hash.c (rb_any_hash): remove unnecessary dsym check
diff --git a/benchmark/bm_hash_aref_sym.rb b/benchmark/bm_hash_aref_sym.rb
index 54298ffc9e..f75d163fe6 100644
--- a/benchmark/bm_hash_aref_sym.rb
+++ b/benchmark/bm_hash_aref_sym.rb
@@ -1,4 +1,9 @@
h = {}
-syms = ('a'..'z').to_a.map(&:to_sym)
+syms = ('a'..'z').to_a
+begin
+ syms = eval("%i[#{syms.join(' ')}]")
+rescue SyntaxError # <= 1.9.3
+ syms.map!(&:to_sym)
+end
syms.each { |s| h[s] = s }
200_000.times { syms.each { |s| h[s] } }
diff --git a/benchmark/bm_hash_aref_sym_long.rb b/benchmark/bm_hash_aref_sym_long.rb
index a9be4059e6..9dab8df7be 100644
--- a/benchmark/bm_hash_aref_sym_long.rb
+++ b/benchmark/bm_hash_aref_sym_long.rb
@@ -3,6 +3,11 @@ syms = %w[puts warn syswrite write stat bacon lettuce tomato
some symbols in this array may already be interned others should not be
hash browns make good breakfast but not cooked using prime numbers
shift for division entries delete_if keys exist?
-].map!(&:to_sym)
+]
+begin
+ syms = eval("%i[#{syms.join(' ')}]")
+rescue SyntaxError # <= 1.9.3
+ syms.map!(&:to_sym)
+end
syms.each { |s| h[s] = s }
200_000.times { syms.each { |s| h[s] } }