[前][次][番号順一覧][スレッド一覧]

ruby-changes:35772

From: normal <ko1@a...>
Date: Thu, 9 Oct 2014 12:44:23 +0900 (JST)
Subject: [ruby-changes:35772] normal:r47854 (trunk): benchmark/bm_hash_aref_sym*.rb: force static symbols

normal	2014-10-09 12:44:12 +0900 (Thu, 09 Oct 2014)

  New Revision: 47854

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47854

  Log:
    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.

  Modified files:
    trunk/ChangeLog
    trunk/benchmark/bm_hash_aref_sym.rb
    trunk/benchmark/bm_hash_aref_sym_long.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 47853)
+++ ChangeLog	(revision 47854)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Oct  9 12:40:28 2014  Eric Wong  <e@8...>
+
+	* benchmark/bm_hash_aref_sym*.rb: force static symbols
+
 Thu Oct  9 12:38:28 2014  Eric Wong  <e@8...>
 
 	* hash.c (rb_any_hash): remove unnecessary dsym check
Index: benchmark/bm_hash_aref_sym_long.rb
===================================================================
--- benchmark/bm_hash_aref_sym_long.rb	(revision 47853)
+++ benchmark/bm_hash_aref_sym_long.rb	(revision 47854)
@@ -3,6 +3,11 @@ syms = %w[puts warn syswrite write stat https://github.com/ruby/ruby/blob/trunk/benchmark/bm_hash_aref_sym_long.rb#L3
 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] } }
Index: benchmark/bm_hash_aref_sym.rb
===================================================================
--- benchmark/bm_hash_aref_sym.rb	(revision 47853)
+++ benchmark/bm_hash_aref_sym.rb	(revision 47854)
@@ -1,4 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/benchmark/bm_hash_aref_sym.rb#L1
 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] } }

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]