Skip to content

Instantly share code, notes, and snippets.

@headius
Created August 1, 2008 09:07
Show Gist options
  • Save headius/3597 to your computer and use it in GitHub Desktop.
Save headius/3597 to your computer and use it in GitHub Desktop.
~/NetBeansProjects/jruby ➔ cat test/bench/bench_thread_creation.rb
require 'benchmark'
(ARGV[0] || 10).to_i.times do
Benchmark.bm(20) do |bm|
bm.report('control loop') { 10_000.times { 1 } }
bm.report('Thread.new.join loop') { 10_000.times { Thread.new { 1 }.join } }
end
end
~/NetBeansProjects/jruby ➔ jruby --server test/bench/bench_thread_creation.rb 5
user system total real
control loop 0.203000 0.000000 0.203000 ( 0.202630)
Thread.new.join loop 3.196000 0.000000 3.196000 ( 3.195984)
user system total real
control loop 0.006000 0.000000 0.006000 ( 0.005816)
Thread.new.join loop 2.729000 0.000000 2.729000 ( 2.728205)
user system total real
control loop 0.002000 0.000000 0.002000 ( 0.002222)
Thread.new.join loop 1.982000 0.000000 1.982000 ( 1.981994)
user system total real
control loop 0.001000 0.000000 0.001000 ( 0.001320)
Thread.new.join loop 2.059000 0.000000 2.059000 ( 2.059305)
user system total real
control loop 0.001000 0.000000 0.001000 ( 0.001289)
Thread.new.join loop 1.955000 0.000000 1.955000 ( 1.955280)
~/NetBeansProjects/jruby ➔ jruby -J-Djruby.thread.pool.enabled=true --server test/bench/bench_thread_creation.rb 5
user system total real
control loop 0.179000 0.000000 0.179000 ( 0.178242)
Thread.new.join loop 1.572000 0.000000 1.572000 ( 1.573915)
user system total real
control loop 0.012000 0.000000 0.012000 ( 0.006952)
Thread.new.join loop 1.082000 0.000000 1.082000 ( 1.082589)
user system total real
control loop 0.003000 0.000000 0.003000 ( 0.003126)
Thread.new.join loop 0.580000 0.000000 0.580000 ( 0.580560)
user system total real
control loop 0.002000 0.000000 0.002000 ( 0.001294)
Thread.new.join loop 0.605000 0.000000 0.605000 ( 0.605378)
user system total real
control loop 0.003000 0.000000 0.003000 ( 0.002854)
Thread.new.join loop 0.543000 0.000000 0.543000 ( 0.542308)
~/NetBeansProjects/jruby ➔ /opt/local/bin/ruby test/bench/bench_thread_creation.rb 5
user system total real
control loop 0.010000 0.000000 0.010000 ( 0.002354)
Thread.new.join loop 0.260000 0.250000 0.510000 ( 0.521613)
user system total real
control loop 0.000000 0.000000 0.000000 ( 0.002005)
Thread.new.join loop 0.270000 0.240000 0.510000 ( 0.519673)
user system total real
control loop 0.000000 0.000000 0.000000 ( 0.001724)
Thread.new.join loop 0.260000 0.250000 0.510000 ( 0.519492)
user system total real
control loop 0.000000 0.000000 0.000000 ( 0.001570)
Thread.new.join loop 0.270000 0.240000 0.510000 ( 0.515869)
user system total real
control loop 0.000000 0.000000 0.000000 ( 0.001550)
Thread.new.join loop 0.260000 0.240000 0.500000 ( 0.521391)
~/NetBeansProjects/jruby ➔ ../ruby1.9/ruby -I ../ruby1.9/lib test/bench/bench_thread_creation.rb 5
user system total real
control loop 0.000000 0.000000 0.000000 ( 0.001757)
Thread.new.join loop 0.280000 0.570000 0.850000 ( 0.650961)
user system total real
control loop 0.010000 0.000000 0.010000 ( 0.001508)
Thread.new.join loop 0.280000 0.570000 0.850000 ( 0.633450)
user system total real
control loop 0.000000 0.000000 0.000000 ( 0.001170)
Thread.new.join loop 0.280000 0.570000 0.850000 ( 0.641375)
user system total real
control loop 0.000000 0.000000 0.000000 ( 0.001144)
Thread.new.join loop 0.280000 0.560000 0.840000 ( 0.642496)
user system total real
control loop 0.000000 0.000000 0.000000 ( 0.001233)
Thread.new.join loop 0.280000 0.570000 0.850000 ( 0.639463)
~/NetBeansProjects/jruby ➔ ../rubinius/bin/rbx test/bench/bench_thread_creation.rb 5
user system total real
control loop 0.002464 0.000000 0.002464 ( 0.002445)
Thread.new.join loop 27.212328 0.000000 27.212328 ( 27.212360)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment