Skip to content
This repository
tree: 5676584e13
Fetching contributors…

Cannot retrieve contributors at this time

executable file 39 lines (33 sloc) 0.59 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
#!/usr/bin/env ruby

def pi(i)
  pi= 0
  num= 4.0
  den= 1
  plus= true

  while den < 5e7
    if plus
      pi+= num/den
      plus= false
    else
      pi-= num/den
      plus= true
    end
    den+= 2
  end
  puts "#{pi} -> #{i}"
end

threads=[]
count=ARGV.shift || 1
puts "Using #{count} threads"

t= Time.new
count.to_i.times do |i|
  threads << Thread.new{pi(i)}
end

threads.each do |j|
  j.join
end

t= (Time.new- t)* 1e3
tps= Integer(count) * 1e3 / t
puts "\nTiempo total (ms) -> %.0f" % t
puts "Threads por segundo -> %.1f" % tps
puts "Total de threads ejecutadas -> #{count}"
Something went wrong with that request. Please try again.