Skip to content

Instantly share code, notes, and snippets.

@headius
Created August 9, 2016 16:27
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/d9fd1c15bef03138a7de2cb857618c41 to your computer and use it in GitHub Desktop.
Save headius/d9fd1c15bef03138a7de2cb857618c41 to your computer and use it in GitHub Desktop.
Partial sums benchmark across JRuby configurations
N=1000_000_000
def threaded_partial_sum(nthreads, n)
puts "Partial sum on #{nthreads} thread(s)"
sum = nthreads.times.collect { 0 }
t1 = Time.now
threads = nthreads.times.collect do |num|
Thread.new do
i=num
psum = 0
while (i <= n) do
psum = psum + i
i = i + nthreads
end
sum[num] = psum
end
end
threads.each(&:join)
total=0
sum.each do |s| total = total + s end
puts "Run took #{Time.now-t1} seconds"
puts total
end
#threaded_partial_sum(1, N)
#threaded_partial_sum(2, N)
#threaded_partial_sum(3, N)
threaded_partial_sum(1, N)
threaded_partial_sum(2, N)
threaded_partial_sum(3, N)
threaded_partial_sum(4, N)
threaded_partial_sum(1, N)
threaded_partial_sum(2, N)
threaded_partial_sum(3, N)
threaded_partial_sum(4, N)

JRuby + Truffle on Graal HEAD

[] ~/projects/jruby $ tool/jt.rb run --graal sums.rb
java version "1.8.0_92"
Java(TM) SE Runtime Environment (build 1.8.0_92-b14)
OpenJDK 64-Bit Server VM (build 25.71-b01-internal-jvmci-0.19-dev, mixed mode)
$ JAVACMD=/Users/headius/projects/graal/graal-jvmci-8/jdk1.8.0_92/product/bin/java /Users/headius/projects/jruby/bin/jruby -X+T -Xtruffle.core.load_path=/Users/headius/projects/jruby/truffle/src/main/ruby -J-server -J-XX:+UnlockExperimentalVMOptions -J-XX:+EnableJVMCI -J-d64 -J-Djvmci.class.path.append=/Users/headius/projects/graal/mxbuild/dists/graal.jar -J-Xbootclasspath/a:/Users/headius/projects/truffle/mxbuild/dists/truffle-api.jar -J-Djvmci.Compiler=graal sums.rb
Partial sum on 1 thread(s)
Run took 7.969 seconds
500000000500000000
Partial sum on 2 thread(s)
Run took 7.599 seconds
500000000500000000
Partial sum on 3 thread(s)
Run took 5.68 seconds
500000000500000000
Partial sum on 4 thread(s)
Run took 4.463 seconds
500000000500000000
Partial sum on 1 thread(s)
Run took 1.365 seconds
500000000500000000
Partial sum on 2 thread(s)
Run took 0.656 seconds
500000000500000000
Partial sum on 3 thread(s)
Run took 0.454 seconds
500000000500000000
Partial sum on 4 thread(s)
Run took 0.452 seconds
500000000500000000

JRuby + Invokedynamic on tweaked Graal

[] ~/projects/graal $ mx/mx vm -Djava.lang.invoke.MethodHandle.PROFILE_GWT=false -XX:+UseJVMCICompiler -Djruby.home=/Users/headius/projects/jruby -Djruby.compile.invokedynamic -Djruby.fixnum.cache=false -jar ../jruby/lib/jruby.jar ../jruby/sums.rb 
Partial sum on 1 thread(s)
Run took 3.124 seconds
500000000500000000
Partial sum on 2 thread(s)
Run took 1.738 seconds
500000000500000000
Partial sum on 3 thread(s)
Run took 1.053 seconds
500000000500000000
Partial sum on 4 thread(s)
Run took 0.892 seconds
500000000500000000
Partial sum on 1 thread(s)
Run took 3.129 seconds
500000000500000000
Partial sum on 2 thread(s)
Run took 1.532 seconds
500000000500000000
Partial sum on 3 thread(s)
Run took 1.067 seconds
500000000500000000
Partial sum on 4 thread(s)
Run took 0.934 seconds
500000000500000000

JRuby + Invokedynamic (GWT profiling OFF) on Graal HEAD

[] ~/projects/graal $ mx/mx vm -Djava.lang.invoke.MethodHandle.PROFILE_GWT=false -XX:+UseJVMCICompiler -Djruby.home=/Users/headius/projects/jruby -Djruby.compile.invokedynamic -Djruby.fixnum.cache=true -jar ../jruby/lib/jruby.jar ../jruby/sums.rb 
Partial sum on 1 thread(s)
Run took 17.054 seconds
500000000500000000
Partial sum on 2 thread(s)
Run took 10.111 seconds
500000000500000000
Partial sum on 3 thread(s)
Run took 9.757 seconds
500000000500000000
Partial sum on 4 thread(s)
Run took 10.052 seconds
500000000500000000
Partial sum on 1 thread(s)
Run took 16.454 seconds
500000000500000000
Partial sum on 2 thread(s)
Run took 10.071 seconds
500000000500000000
Partial sum on 3 thread(s)
Run took 9.674 seconds
500000000500000000
Partial sum on 4 thread(s)
Run took 10.094 seconds
500000000500000000

JRuby + Invokedynamic (GWT profiling ON) on Graal HEAD

[] ~/projects/graal $ mx/mx vm -Djava.lang.invoke.MethodHandle.PROFILE_GWT=true -XX:+UseJVMCICompiler -Djruby.home=/Users/headius/projects/jruby -Djruby.compile.invokedynamic -Djruby.fixnum.cache=true -jar ../jruby/lib/jruby.jar ../jruby/sums.rb 
Partial sum on 1 thread(s)
Run took 15.924 seconds
500000000500000000
Partial sum on 2 thread(s)
Run took 51.19 seconds
500000000500000000
Partial sum on 3 thread(s)
Run took 53.954 seconds
500000000500000000
Partial sum on 4 thread(s)
Run took 55.477 seconds
500000000500000000
Partial sum on 1 thread(s)
Run took 15.029 seconds
500000000500000000
Partial sum on 2 thread(s)
Run took 51.471 seconds
500000000500000000
Partial sum on 3 thread(s)
Run took 53.796 seconds
500000000500000000
Partial sum on 4 thread(s)
Run took 53.295 seconds
500000000500000000

JRuby + Invokedynamic on Hotspot 1.8.0_92

[] ~/projects/graal $ mx/mx vm -Djava.lang.invoke.MethodHandle.PROFILE_GWT=true -XX:-UseJVMCICompiler -Djruby.home=/Users/headius/projects/jruby -Djruby.compile.invokedynamic -Djruby.fixnum.cache=true -jar ../jruby/lib/jruby.jar ../jruby/sums.rb 
Partial sum on 1 thread(s)
Run took 21.137 seconds
500000000500000000
Partial sum on 2 thread(s)
Run took 11.111 seconds
500000000500000000
Partial sum on 3 thread(s)
Run took 9.93 seconds
500000000500000000
Partial sum on 4 thread(s)
Run took 10.066 seconds
500000000500000000
Partial sum on 1 thread(s)
Run took 22.813 seconds
500000000500000000
Partial sum on 2 thread(s)
Run took 11.94 seconds
500000000500000000
Partial sum on 3 thread(s)
Run took 10.013 seconds
500000000500000000
Partial sum on 4 thread(s)
Run took 9.796 seconds
500000000500000000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment