This file contains 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
#gem install fibur | |
#And the lib its just : | |
#Fibur = Thread | |
#https://github.com/tenderlove/fibur/blob/master/lib/fibur.rb | |
#:) | |
require 'benchmark' | |
require 'net/http' | |
require 'uri' | |
require 'fibur' # use the Fibur gem. | |
def network_read(uri) | |
Net::HTTP.get_response uri | |
end | |
n = 50000 | |
uri = URI('http://google.com/') | |
Benchmark.bm(5) do |x| | |
x.report('loop') { 100.times { network_read(uri) } } | |
x.report('fibur') { | |
100.times.map { | |
Fibur.new { network_read(uri) } | |
}.map(&:join) | |
} | |
end | |
#➜ Desktop ruby fibur.rb | |
# user system total real | |
#loop 0.120000 0.050000 0.170000 ( 23.593217) | |
#fibur 0.180000 0.060000 0.240000 ( 0.721610) |
No comments:
Post a Comment