Skip to content

Instantly share code, notes, and snippets.

@headius
Created May 31, 2018 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save headius/f7fdf4a39b2233842afe1778ed4523bb to your computer and use it in GitHub Desktop.
Save headius/f7fdf4a39b2233842afe1778ed4523bb to your computer and use it in GitHub Desktop.
JRuby running the "min" challenge after a few tweaks
[] ~/projects/jruby $ cat min.rb
def low_min(a, b)
if a < b
a
else
b
end
end
def high_min(a, b)
[a, b].sort.at(0)
end
20.times {
t = Time.now
i = 0
while i < 100_000_000
low_min(i, i+=1)
end
puts "low: #{Time.now - t}"
t = Time.now
i = 0
while i < 100_000_000
high_min(i, i+=1)
end
puts "high: #{Time.now - t}"
}
[] ~/projects/jruby $ JAVA_OPTS=$GRAAL jruby -Xcompile.invokedynamic -Xfixnum.cache=false min.rb
low: 2.2648550000000003
high: 0.681386
low: 0.35639899999999997
high: 0.16915000000000002
low: 0.094107
high: 0.16881300000000002
low: 0.07174699999999999
high: 0.17848899999999998
low: 0.079235
high: 0.165079
low: 0.09004
high: 0.168719
low: 0.07557
high: 0.178189
low: 0.083259
high: 0.164412
low: 0.090774
high: 0.163765
low: 0.071055
high: 0.182369
low: 0.085164
high: 0.168249
low: 0.08817499999999999
high: 0.160921
low: 0.072628
high: 0.173565
low: 0.07823
high: 0.161287
low: 0.08923199999999999
high: 0.165192
low: 0.070665
high: 0.181875
low: 0.086671
high: 0.162917
low: 0.093394
high: 0.16798600000000002
low: 0.07347999999999999
high: 0.17231
low: 0.081306
high: 0.160564
[] ~/projects/jruby $ ruby -v min.rb
truffleruby 1.0.0-rc1, like ruby 2.3.7 <native build with Graal> [x86_64-darwin]
low: 0.162
high: 0.205
low: 0.073
high: 0.081
low: 0.081
high: 0.092
low: 0.096
high: 0.085
low: 0.088
high: 0.084
low: 0.082
high: 0.083
low: 0.049
high: 0.079
low: 0.051
high: 0.077
low: 0.05
high: 0.08
low: 0.049
high: 0.075
low: 0.047
high: 0.079
low: 0.049
high: 0.082
low: 0.051
high: 0.079
low: 0.048
high: 0.076
low: 0.049
high: 0.081
low: 0.0539999999999999
high: 0.08
low: 0.049
high: 0.078
low: 0.049
high: 0.089
low: 0.056
high: 0.081
low: 0.052
high: 0.077
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment