Skip to content

Instantly share code, notes, and snippets.

@tmm1
Created January 26, 2009 01:22
Show Gist options
  • Select an option

  • Save tmm1/52644 to your computer and use it in GitHub Desktop.

Select an option

Save tmm1/52644 to your computer and use it in GitHub Desktop.
$ cat fbbench.rb
FIBER_NUM = 503
number = ARGV.first.to_i
threads = []
for i in 1..FIBER_NUM
threads << Fiber.new do |num|
while true
Fiber.yield
if number > 0
number -= 1
else
puts num
exit 0
end
end
end
threads.last.resume(i)
end
while true
for thread in threads
thread.resume
end
end
$ time ~joe/ruby-19-svn/miniruby fbbench.rb 500000
19
real 0m0.910s
user 0m0.904s
sys 0m0.008s
$ time ~joe/ruby187/miniruby fbbench.rb 500000
19
real 0m11.659s
user 0m11.537s
sys 0m0.028s
$ time ruby -I fiber18/lib -r fiber18 fbbench.rb 500000
19
real 0m22.866s
user 0m22.753s
sys 0m0.032s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment