Skip to content

Instantly share code, notes, and snippets.

@lucasallan
Created October 9, 2015 05:42
Show Gist options
  • Save lucasallan/1fc43faa8efacda048b9 to your computer and use it in GitHub Desktop.
Save lucasallan/1fc43faa8efacda048b9 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'concurrent'
require 'benchmark'
NUM = 50_000_000
WARM_UPS = NUM
def jruby?
defined? JRUBY_VERSION
end
def version
gem_dir = Gem::Specification.find_by_name('concurrent-ruby').gem_dir
File.open(File.join(gem_dir, 'VERSION'), 'r').read
rescue
'unknown'
end
puts "~~~ Ruby version: #{RUBY_VERSION}"
if jruby?
puts "~~~ JRuby version: #{JRUBY_VERSION}"
else
puts "~~~ Ruby engine: #{RUBY_ENGINE}"
end
puts "~~~ Gem version: #{version}"
Benchmark.bm do |stats|
puts "Benchmarking #{Concurrent::Atom}..."
ref = Concurrent::Atom.new('foo')
value = nil
puts 'Before JVM warm-up...' if jruby?
stats.report do
NUM.times { value = ref.value }
end
if jruby?
WARM_UPS.times { value = ref.value }
puts 'After JVM warm-up...'
stats.report do
NUM.times { value = ref.value }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment