Created
September 22, 2014 05:15
-
-
Save SpringMT/da7eb120744d9d09fa8d to your computer and use it in GitHub Desktop.
htm bench script
This file contains 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' | |
r = 1_000_000 | |
rsqr = r*r | |
iteration = 100_000 | |
threads= [] | |
mutex = Mutex.new | |
cnt = [0, 0] | |
puts Benchmark.measure { | |
16.times do | |
t = Thread.new do | |
iteration.times do | |
x = rand(2*r) - r | |
x = x*x | |
y = rand(2*r) - r | |
y = y*y | |
i = (x+y) / rsqr | |
mutex.synchronize do | |
cnt[i] = cnt.at(i) + 1 | |
end | |
end | |
end | |
threads << t | |
end | |
threads.each do |t| | |
t.join | |
end | |
num = cnt[0] * 4 | |
den = iteration * 16 | |
puts num / den.to_f | |
puts Benchmark::CAPTION | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment