-
-
Notifications
You must be signed in to change notification settings - Fork 942
Description
Using a (very simple) benchmark to test how JRuby handles differing scopes for variables, I found that unlike MRI 2.2.2, JRuby 9.0.1.0 was performing far slower than other variable types / scopes with globals.
The test code is as follows:
require 'benchmark'
LOOPS = 30000000
$global = 0
@outer_inst = 0
outer_scope = 0
Benchmark.bmbm {|test|
@inner_inst = 0
inner_scope = 0
test.report('$global'){ LOOPS.times { $global += 1 } }
test.report('@outer_inst'){ LOOPS.times { @outer_inst += 1 } }
test.report('outer_scope'){ LOOPS.times { outer_scope += 1 } }
test.report('@inner_inst'){ LOOPS.times { @inner_inst += 1 } }
test.report('inner_scope'){ LOOPS.times { inner_scope += 1 } }
test.report('local_scope'){ local_scope = 0; LOOPS.times { local_scope += 1 } }
}The results for JRuby:
jruby 9.0.1.0 (2.2.2) 2015-09-02 583f336 Java HotSpot(TM) 64-Bit Server VM 25.51-b03 on 1.8.0_51-b16 +jit [Windows 7-amd64]
Rehearsal -----------------------------------------------
$global 6.167000 0.000000 6.167000 ( 6.167375)
@outer_inst 2.830000 0.000000 2.830000 ( 2.829050)
outer_scope 2.777000 0.000000 2.777000 ( 2.776937)
@inner_inst 3.118000 0.000000 3.118000 ( 3.117344)
inner_scope 2.631000 0.000000 2.631000 ( 2.630262)
local_scope 2.297000 0.000000 2.297000 ( 2.297344)
------------------------------------- total: 19.820000sec
user system total real
$global 6.164000 0.000000 6.164000 ( 6.162756)
@outer_inst 3.078000 0.000000 3.078000 ( 3.077359)
outer_scope 2.360000 0.000000 2.360000 ( 2.359673)
@inner_inst 2.614000 0.000000 2.614000 ( 2.614211)
inner_scope 2.384000 0.000000 2.384000 ( 2.384571)
local_scope 2.462000 0.000000 2.462000 ( 2.461775)
And MRI:
ruby 2.2.2p95 (2015-04-13 revision 50295) [x64-mingw32]
Rehearsal -----------------------------------------------
$global 5.086000 0.000000 5.086000 ( 5.099396)
@outer_inst 5.272000 0.000000 5.272000 ( 5.281465)
outer_scope 4.821000 0.016000 4.837000 ( 4.832652)
@inner_inst 4.305000 0.000000 4.305000 ( 4.335950)
inner_scope 4.727000 0.000000 4.727000 ( 4.745273)
local_scope 5.101000 0.000000 5.101000 ( 5.102266)
------------------------------------- total: 29.328000sec
user system total real
$global 4.759000 0.000000 4.759000 ( 4.764358)
@outer_inst 5.335000 0.000000 5.335000 ( 5.348511)
outer_scope 5.179000 0.000000 5.179000 ( 5.180154)
@inner_inst 5.429000 0.000000 5.429000 ( 5.503256)
inner_scope 4.929000 0.000000 4.929000 ( 4.937495)
local_scope 4.556000 0.015000 4.571000 ( 4.567554)
It seems that while MRI is fairly normalized across the board, JRuby only shows relatively equal times for local, inner, and instance variable scopes. In particular, JRuby's time for globals is ~226% of the average of all other tested scopes.
The good news, however, is that JRuby's jitting is definitely resulting in faster overall performance.