Created
January 26, 2009 01:22
-
-
Save tmm1/52644 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| $ 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