Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'benchmark'
- def fib(n)
- n < 2 ? n : fib(n-1) + fib(n-2)
- end
- def test(thread_qty,fib_qty)
- puts "\n#{self.class.name}##{__method__} .. thread_qty: #{thread_qty}, fib_qty: #{fib_qty}"
- puts Benchmark.measure{
- count = 0
- arr = []
- thread_qty.times do |i|
- arr[i] = Thread.new {
- # sleep(rand/qty)
- fib(fib_qty)
- Thread.current["mycount"] = count
- count += 1
- }
- end
- arr.each {|t| t.join; print t["mycount"], ", " }
- puts "count = #{count}"
- }
- puts "\n"
- end
- test(4,1)
- test(4,2)
- test(4,4)
- test(4,8)
- test(4,16)
- test(4,32)
- test(4,48)
- # test(4,64)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement