Created
March 16, 2012 00:31
-
-
Save jkutner/2047877 to your computer and use it in GitHub Desktop.
Trying running these programs on MRI and JRuby!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
def factorial_repeat(k, x) | |
k.times { x.downto(1).inject(:*) } | |
end | |
def run(i, k, x) | |
i.downto(1).map do | |
Thread.new { factorial_repeat(k, x) } | |
end.each { |t| t.join } | |
end | |
puts Benchmark.measure { run(1, 400_000, 99) } | |
puts Benchmark.measure { run(4, 100_000, 99) } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
def run(x) | |
data = [] | |
(1..x).map do |m| | |
Thread.new do | |
x.times do |n| | |
data << m * n | |
end | |
end | |
end.each {|t| t.join} | |
puts "size=#{data.size}" | |
puts "nils=#{data.size-data.compact.size}" | |
end | |
puts Benchmark.measure { run(32) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment