summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authork0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-04-20 13:42:08 +0000
committerk0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-04-20 13:42:08 +0000
commite72a86fc9373e4477b6e275735fecdf4eac9944a (patch)
tree568dcbf1a8681ba3d7b9289c7243b83b5cd610d7 /test/ruby
parent1658fb3f8383de32059e3f6620ed8742c08d2a9e (diff)
_mjit_compile_send.erb: inline attr_reader call
_mjit_compile_send_guard.erb: carve out the shared logic to invalidate inlined method call common.mk: update dependency for this change test_jit.rb: add test for attr_reader optimization * Benchmark ``` require 'benchmark_driver' Benchmark.driver do |x| x.prelude %{ class C attr_reader :a def initialize @a = 1 end end o = C.new def l o i = 0 while i < 1000000 o.a i += 1 end end } x.report 'aread', %{ l o } x.loop_count 1000 x.rbenv 'before', 'before,--jit', 'after,--jit' x.verbose end ``` ``` before: ruby 2.6.0dev (2018-04-20 trunk 63211) [x86_64-linux] before,--jit: ruby 2.6.0dev (2018-04-20 trunk 63211) +JIT [x86_64-linux] after,--jit: ruby 2.6.0dev (2018-04-20 trunk 63211) +JIT [x86_64-linux] last_commit=_mjit_compile_send.erb: inline attr_reader call Calculating ------------------------------------- before before,--jit after,--jit aread 54.597 122.894 218.574 i/s - 1.000k times in 18.316102s 8.137089s 4.575106s Comparison: aread after,--jit: 218.6 i/s before,--jit: 122.9 i/s - 1.78x slower before: 54.6 i/s - 4.00x slower ``` * Optcarrot A little made faster? fps: 71.35 -> 72.11 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63212 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_jit.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/test/ruby/test_jit.rb b/test/ruby/test_jit.rb
index f67c8a243c..9b80a90838 100644
--- a/test/ruby/test_jit.rb
+++ b/test/ruby/test_jit.rb
@@ -529,6 +529,41 @@ class TestJIT < Test::Unit::TestCase
end;
end
+ def test_attr_reader
+ assert_eval_with_jit("#{<<~"begin;"}\n#{<<~"end;"}", stdout: "4nil\nnil\n6", success_count: 2, min_calls: 2)
+ begin;
+ class A
+ attr_reader :a, :b
+
+ def initialize
+ @a = 2
+ end
+
+ def test
+ a
+ end
+
+ def undefined
+ b
+ end
+ end
+
+ a = A.new
+ print(a.test * a.test)
+ p(a.undefined)
+ p(a.undefined)
+
+ # redefinition
+ class A
+ def test
+ 3
+ end
+ end
+
+ print(2 * a.test)
+ end;
+ end
+
private
# The shortest way to test one proc