Last active
June 2, 2018 02:47
-
-
Save havenwood/2cfe05dd66b9227706412535c32ed41b to your computer and use it in GitHub Desktop.
Benchmarks Comparing First Hash Key in CRuby, JRuby, TruffleRuby and Rubinius
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~ chruby ruby-2.5.1 | |
~ ruby -v | |
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17] | |
~ ruby first_key_bench.rb | |
Warming up -------------------------------------- | |
keys 238.442k i/100ms | |
each_key 114.229k i/100ms | |
first 153.335k i/100ms | |
flatten 229.021k i/100ms | |
Calculating ------------------------------------- | |
keys 7.163M (± 4.2%) i/s - 35.766M in 5.002627s | |
each_key 1.813M (± 2.8%) i/s - 9.138M in 5.043558s | |
first 2.525M (± 3.0%) i/s - 12.727M in 5.044937s | |
flatten 5.920M (± 3.0%) i/s - 29.773M in 5.033696s | |
Comparison: | |
keys: 7162938.3 i/s | |
flatten: 5920454.4 i/s - 1.21x slower | |
first: 2525033.6 i/s - 2.84x slower | |
each_key: 1813436.5 i/s - 3.95x slower | |
~ | |
~ chruby jruby | |
~ ruby -v | |
jruby 9.2.0.0 (2.5.0) 2018-05-24 81156a8 GraalVM 1.0.0-rc1 25.71-b01-internal-jvmci-0.42 on 1.8.0_161-b12 +jit [darwin-x86_64] | |
~ ruby -Xcompile.invokedynamic first_key_bench.rb | |
Warming up -------------------------------------- | |
keys 190.567k i/100ms | |
each_key 55.809k i/100ms | |
first 246.750k i/100ms | |
flatten 136.328k i/100ms | |
Calculating ------------------------------------- | |
keys 39.866M (± 9.4%) i/s - 196.665M in 4.992307s | |
each_key 1.494M (±40.9%) i/s - 4.744M in 5.026491s | |
first 21.614M (±10.2%) i/s - 106.349M in 4.998362s | |
flatten 3.382M (± 5.3%) i/s - 16.905M in 5.013187s | |
Comparison: | |
keys: 39865568.1 i/s | |
first: 21613530.8 i/s - 1.84x slower | |
flatten: 3381734.0 i/s - 11.79x slower | |
each_key: 1494299.7 i/s - 26.68x slower | |
~ | |
~ chruby truffleruby | |
~ ruby -v | |
truffleruby 1.0.0-rc1, like ruby 2.3.7 <native build with Graal> [x86_64-darwin] | |
~ ruby first_key_bench.rb | |
Warming up -------------------------------------- | |
keys 1.412M i/100ms | |
each_key 1.961M i/100ms | |
first 1.782M i/100ms | |
flatten 306.020k i/100ms | |
Calculating ------------------------------------- | |
keys 42.110M (±38.5%) i/s - 169.434M in 5.000957s | |
each_key 611.510M (± 7.3%) i/s - 2.665B in 4.992264s | |
first 23.136M (±26.5%) i/s - 103.335M in 5.024682s | |
flatten 4.840M (±25.1%) i/s - 22.033M in 5.041441s | |
Comparison: | |
each_key: 611510252.3 i/s | |
keys: 42109687.3 i/s - 14.52x slower | |
first: 23135572.4 i/s - 26.43x slower | |
flatten: 4840388.0 i/s - 126.33x slower | |
~ | |
~ chruby rbx | |
~ ruby -v | |
rubinius 3.104 (2.3.1 eced203d 2018-05-15 4.0.1) [x86_64-darwin17.5.0] | |
~ ruby first_key_bench.rb | |
Warming up -------------------------------------- | |
keys 36.392k i/100ms | |
each_key 14.339k i/100ms | |
first 45.738k i/100ms | |
flatten 16.239k i/100ms | |
Calculating ------------------------------------- | |
keys 626.855k (± 6.3%) i/s - 3.130M | |
each_key 192.763k (±11.0%) i/s - 960.713k | |
first 827.696k (± 8.3%) i/s - 4.116M | |
flatten 204.028k (± 5.5%) i/s - 1.023M | |
Comparison: | |
first: 827696.4 i/s | |
keys: 626854.8 i/s - 1.32x slower | |
flatten: 204027.9 i/s - 4.06x slower | |
each_key: 192763.2 i/s - 4.29x slower |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark/ips' | |
Benchmark.ips do |x| | |
H = {key: :value}.freeze | |
x.report('keys') { H.keys.first } | |
x.report('each_key') { H.each_key.first } | |
x.report('first') { H.first.first } | |
x.report('flatten') { H.flatten.first } | |
x.compare! | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment