ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]
Warming up --------------------------------------
old 136.393k i/100ms
new 166.558k i/100ms
Calculating -------------------------------------
old 2.057M (± 1.6%) i/s - 10.366M in 5.040331s
new 2.760M (± 1.9%) i/s - 13.824M in 5.010739s
Comparison:
new: 2759913.3 i/s
old: 2057122.0 i/s - 1.34x slower
jruby 9.2.0.0 (2.5.0) 2018-05-24 81156a8 Java HotSpot(TM) 64-Bit Server VM 25.161-b12 on 1.8.0_161-b12 +jit [darwin-x86_64]
Warming up --------------------------------------
old 130.474k i/100ms
new 168.340k i/100ms
Calculating -------------------------------------
old 4.630M (± 4.4%) i/s - 23.094M in 4.998427s
new 6.036M (± 3.1%) i/s - 30.133M in 4.996735s
Comparison:
new: 6036423.5 i/s
old: 4630192.2 i/s - 1.30x slower
truffleruby 1.0.0-rc5, like ruby 2.4.4, GraalVM EE Native [x86_64-darwin]
Warming up --------------------------------------
old 2.596M i/100ms
new 2.566M i/100ms
Calculating -------------------------------------
old 157.205M (± 7.9%) i/s - 763.196M in 5.007716s
new 161.206M (± 5.9%) i/s - 790.439M in 5.002986s
Comparison:
new: 161205838.1 i/s
old: 157204791.3 i/s - same-ish: difference falls within error
truffleruby 1.0.0-rc5, like ruby 2.4.4, GraalVM CE Native [x86_64-darwin]
Warming up --------------------------------------
old 2.251M i/100ms
new 2.234M i/100ms
Calculating -------------------------------------
old 2.651B (± 8.5%) i/s - 12.642B in 4.979541s
new 563.949M (± 5.0%) i/s - 2.730B in 4.997289s
Comparison:
old: 2651034814.3 i/s
new: 563948800.5 i/s - 4.70x slower
No performance difference for the two methods in TruffleRuby - no need to manually do the optimisation, TruffleRuby's compiler does it for you.
And it's it's 58x faster in the first place (JRuby 2x faster).