Sha256: 778b4c4def7651db183f69ffc2e2e716dc658cc7139d4f8352bafe897a5fbfdb

Contents?: true

Size: 708 Bytes

Versions: 100

Compression:

Stored size: 708 Bytes

Contents

#!/usr/bin/env ruby
# encoding: utf-8

require "rubygems"
require "set"
require "thread"
require "benchmark"
require "monitor"

puts
puts "-" * 80
puts "Benchmarking on #{RUBY_DESCRIPTION}"

n  = 2_000_000
mx = Mutex.new
mt = Monitor.new

# warm up the JIT, etc
puts "Doing a warmup run..."
n.times do |i|
  mx.synchronize { 1 }
  mt.synchronize { 1 }
end

t1  = Benchmark.realtime do
  n.times do |i|
    mx.synchronize { 1 }
  end
end
r1  = (n.to_f/t1.to_f)

t2  = Benchmark.realtime do
  n.times do |i|
    mt.synchronize { 1 }
  end
end
r2  = (n.to_f/t2.to_f)

puts "Mutex#synchronize, rate: #{(r1 / 1000).round(2)} KGHz"
puts "Monitor#synchronize, rate: #{(r2 / 1000).round(2)} KGHz"
puts
puts "-" * 80

Version data entries

100 entries across 100 versions & 1 rubygems

Version Path
bunny-1.7.1 benchmarks/mutex_and_monitor.rb
bunny-2.1.0 benchmarks/mutex_and_monitor.rb
bunny-2.0.1 benchmarks/mutex_and_monitor.rb
bunny-2.0.0 benchmarks/mutex_and_monitor.rb
bunny-2.0.0.rc2 benchmarks/mutex_and_monitor.rb
bunny-2.0.0.rc1 benchmarks/mutex_and_monitor.rb
bunny-1.7.0 benchmarks/mutex_and_monitor.rb
bunny-1.6.3 benchmarks/mutex_and_monitor.rb
bunny-1.6.2 benchmarks/mutex_and_monitor.rb
bunny-1.6.1 benchmarks/mutex_and_monitor.rb
bunny-1.6.0 benchmarks/mutex_and_monitor.rb
bunny-1.5.1 benchmarks/mutex_and_monitor.rb
bunny-1.6.0.rc2 benchmarks/mutex_and_monitor.rb
bunny-1.6.0.rc1 benchmarks/mutex_and_monitor.rb
bunny-1.6.0.pre1 benchmarks/mutex_and_monitor.rb
bunny-1.5.0 benchmarks/mutex_and_monitor.rb
bunny-1.5.0.pre2 benchmarks/mutex_and_monitor.rb
bunny-1.5.0.pre1 benchmarks/mutex_and_monitor.rb
bunny-1.4.1 benchmarks/mutex_and_monitor.rb
bunny-1.4.0 benchmarks/mutex_and_monitor.rb