Created
March 31, 2018 12:52
-
-
Save webuilder240/22ea9304be7d995147528f0e6713ba59 to your computer and use it in GitHub Desktop.
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
require 'rubygems' | |
require 'benchmark' | |
require 'faraday' | |
require 'typhoeus' | |
require 'typhoeus/adapters/faraday' | |
API_URL = 'https://safe-inlet-51629.herokuapp.com/' | |
Benchmark.bm 10 do |r| | |
r.report "not parallel (net_http)" do | |
responses = [] | |
conn = Faraday.new(url: API_URL) { |builder| builder.adapter :net_http } | |
20.times do |n| | |
responses << conn.get("/hoge/#{n}") | |
end | |
end | |
r.report "parallel (typhoeus)" do | |
responses = [] | |
conn = Faraday.new(url: API_URL) { |faraday| faraday.adapter :typhoeus } | |
conn.in_parallel do | |
20.times do |n| | |
responses << conn.get("/hoge/#{n}") | |
end | |
end | |
end | |
end |
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
user system total real | |
not parallel (net_http) 0.299139 0.047404 0.346543 ( 17.354107) | |
parallel (typhoeus) 0.077517 0.029078 0.106595 ( 0.842841) |
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
require 'rubygems' | |
require 'benchmark' | |
require 'faraday' | |
require 'typhoeus' | |
require 'typhoeus/adapters/faraday' | |
API_URL = 'https://safe-inlet-51629.herokuapp.com/' | |
responses = [] | |
puts '==================== not_parallel_responses =============================' | |
conn = Faraday.new(url: API_URL) { |builder| builder.adapter :net_http } | |
20.times do |n| | |
responses << conn.get("/hoge/#{n}") | |
end | |
responses.map { |res, i| puts "#{res.env.url}" } | |
puts '==================== not_parallel_responses_end =============================' | |
responses = [] | |
puts '==================== parallel_responses =============================' | |
conn = Faraday.new(url: API_URL) { |faraday| faraday.adapter :typhoeus } | |
conn.in_parallel do | |
20.times do |n| | |
responses << conn.get("/hoge/#{n}") | |
end | |
end | |
responses.map { |res, i| puts "#{res.env.url}" } | |
puts '==================== parallel_responses_end =============================' |
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
==================== not_parallel_responses ============================= | |
https://safe-inlet-51629.herokuapp.com/hoge/0 | |
https://safe-inlet-51629.herokuapp.com/hoge/1 | |
https://safe-inlet-51629.herokuapp.com/hoge/2 | |
https://safe-inlet-51629.herokuapp.com/hoge/3 | |
https://safe-inlet-51629.herokuapp.com/hoge/4 | |
https://safe-inlet-51629.herokuapp.com/hoge/5 | |
https://safe-inlet-51629.herokuapp.com/hoge/6 | |
https://safe-inlet-51629.herokuapp.com/hoge/7 | |
https://safe-inlet-51629.herokuapp.com/hoge/8 | |
https://safe-inlet-51629.herokuapp.com/hoge/9 | |
https://safe-inlet-51629.herokuapp.com/hoge/10 | |
https://safe-inlet-51629.herokuapp.com/hoge/11 | |
https://safe-inlet-51629.herokuapp.com/hoge/12 | |
https://safe-inlet-51629.herokuapp.com/hoge/13 | |
https://safe-inlet-51629.herokuapp.com/hoge/14 | |
https://safe-inlet-51629.herokuapp.com/hoge/15 | |
https://safe-inlet-51629.herokuapp.com/hoge/16 | |
https://safe-inlet-51629.herokuapp.com/hoge/17 | |
https://safe-inlet-51629.herokuapp.com/hoge/18 | |
https://safe-inlet-51629.herokuapp.com/hoge/19 | |
==================== not_parallel_responses_end ============================= | |
==================== parallel_responses ============================= | |
https://safe-inlet-51629.herokuapp.com/hoge/0 | |
https://safe-inlet-51629.herokuapp.com/hoge/1 | |
https://safe-inlet-51629.herokuapp.com/hoge/2 | |
https://safe-inlet-51629.herokuapp.com/hoge/3 | |
https://safe-inlet-51629.herokuapp.com/hoge/4 | |
https://safe-inlet-51629.herokuapp.com/hoge/5 | |
https://safe-inlet-51629.herokuapp.com/hoge/6 | |
https://safe-inlet-51629.herokuapp.com/hoge/7 | |
https://safe-inlet-51629.herokuapp.com/hoge/8 | |
https://safe-inlet-51629.herokuapp.com/hoge/9 | |
https://safe-inlet-51629.herokuapp.com/hoge/10 | |
https://safe-inlet-51629.herokuapp.com/hoge/11 | |
https://safe-inlet-51629.herokuapp.com/hoge/12 | |
https://safe-inlet-51629.herokuapp.com/hoge/13 | |
https://safe-inlet-51629.herokuapp.com/hoge/14 | |
https://safe-inlet-51629.herokuapp.com/hoge/15 | |
https://safe-inlet-51629.herokuapp.com/hoge/16 | |
https://safe-inlet-51629.herokuapp.com/hoge/17 | |
https://safe-inlet-51629.herokuapp.com/hoge/18 | |
https://safe-inlet-51629.herokuapp.com/hoge/19 | |
==================== parallel_responses_end ============================= |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment