Skip to content

Instantly share code, notes, and snippets.

@SpringMT
Created September 19, 2014 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SpringMT/891481b79cf60b5de595 to your computer and use it in GitHub Desktop.
Save SpringMT/891481b79cf60b5de595 to your computer and use it in GitHub Desktop.
thread bench for gobiesvm
r = 1000000
rsqr = r*r
iteration = 10000
cnt = [0, 0]
16.times do
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
cnt.at(i).atomic_add(1)
end
end
end
Join
num = cnt[0] * 4
den = iteration * 16
puts num / den.to_f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment