Skip to content

Instantly share code, notes, and snippets.

@Drakula2k
Forked from EmmanuelOga/r191.txt
Last active August 29, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Drakula2k/10488485 to your computer and use it in GitHub Desktop.
Save Drakula2k/10488485 to your computer and use it in GitHub Desktop.
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-darwin12.0]
curb (0.8.5)
em-http-request (1.1.2)
eventmachine (1.0.3)
typhoeus (0.6.8)
user system total real
4kb std
Memory: 27580
0.000000 0.000000 0.210000 ( 0.224181)
4kb std_thr
Memory: 30076
0.000000 0.000000 0.240000 ( 0.220003)
4kb patron
Memory: 29116
0.000000 0.000000 0.130000 ( 0.143110)
4kb curb
Memory: 43852
0.000000 0.010000 0.120000 ( 0.116356)
4kb em-http
Memory: 27784
0.000000 0.000000 0.190000 ( 0.185659)
4kb typhoeus
Memory: 31536
0.000000 0.000000 0.200000 ( 0.278191)
6m std
Memory: 132848
0.000000 0.000000 2.730000 ( 2.775231)
6m std_thr
Memory: 136748
0.000000 0.000000 3.340000 ( 2.913125)
6m patron
Memory: 108752
0.000000 0.000000 3.080000 ( 3.175116)
6m curb
Memory: 117792
0.000000 0.000000 1.610000 ( 1.620229)
6m em-http
Memory: 172988
0.000000 0.000000 2.680000 ( 2.702788)
6m typhoeus
Memory: 135676
0.000000 0.000000 2.850000 ( 2.918610)
MIXED std
Memory: 143724
0.000000 0.000000 2.830000 ( 2.911066)
MIXED std_thr
Memory: 156664
0.000000 0.010000 3.570000 ( 3.111756)
MIXED patron
Memory: 108940
0.000000 0.000000 3.210000 ( 3.330207)
MIXED curb
Memory: 156540
0.000000 0.000000 1.640000 ( 1.660978)
MIXED em-http
Memory: 144560
0.000000 0.000000 2.930000 ( 2.953328)
MIXED typhoeus
Memory: 117532
0.000000 0.000000 3.030000 ( 3.316971)
rubinius 2.2.6 (2.1.0 68d916a5 2014-03-10 JI) [x86_64-darwin13.1.0]
curb (0.8.5)
em-http-request (1.1.2)
eventmachine (1.0.3)
typhoeus (0.6.8)
user system total real
4kb std
Memory: 77640
0.511507 0.014014 1.495043 ( 0.522788)
4kb std_thr
Memory: 75328
0.296992 0.011305 1.455924 ( 0.333288)
4kb patron
Memory: 35888
0.412215 0.013579 0.915986 ( 0.425925)
4kb curb
Memory: 88712
0.201022 0.010115 0.624651 ( 0.210881)
4kb em-http
Memory: 44856
0.349629 0.016326 1.196351 ( 0.584253)
4kb typhoeus
Memory: 28656
0.000089 0.001430 0.246808 ( 0.275505)
6m std
Memory: 148488
0.000096 0.001203 9.949797 ( 5.117600)
6m std_thr
Memory: 392684
0.000092 0.000936 17.066421 ( 4.672654)
6m patron
Memory: 127208
0.000086 0.000995 4.829983 ( 3.094903)
6m curb
Memory: 173948
0.000086 0.001129 3.751804 ( 2.339566)
6m em-http
Memory: 281792
0.000089 0.000918 11.549134 ( 6.752262)
6m typhoeus
Memory: 203888
0.000083 0.000835 11.792506 ( 6.916763)
MIXED std
Memory: 160284
0.000094 0.001080 10.736349 ( 5.485544)
MIXED std_thr
Memory: 392824
0.000079 0.000952 17.532003 ( 4.675865)
MIXED patron
Memory: 114024
0.000094 0.001053 5.909603 ( 3.419288)
MIXED curb
Memory: 163480
0.000081 0.000870 4.230235 ( 2.480600)
MIXED em-http
Memory: 272896
0.000088 0.000971 12.267878 ( 7.021912)
MIXED typhoeus
Memory: 204676
0.000088 0.001084 11.867485 ( 7.030971)
require 'rubygems'
require 'open-uri'
require 'net/http'
require 'curb'
require 'benchmark'
require 'typhoeus'
require 'em-http-request'
require 'patron'
def http(url)
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
http.read_timeout = 30
http.open_timeout = 30
req = Net::HTTP::Get.new("#{uri.path}?#{uri.query}")
response = http.request(req) rescue nil
response.body
end
def std(urls, path)
urls.each do |uri|
http(uri)
end
end
def std_threaded(urls, path)
pool = []
urls.each do |uri|
pool << Thread.new { http(uri) }
end
pool.each { |t| t.join }
end
def curb(urls,save_path = nil)
downloads = {}
Curl::Multi.get(urls) {|easy| downloads[easy.url] = easy.body_str }
urls.each do |url|
downloads[url]
end
end
def typo(urls, path = nil)
Typhoeus::Config.memoize = false
hydra = Typhoeus::Hydra.new
requests = urls.map { |url| t = Typhoeus::Request.new(url); hydra.queue(t); t }
hydra.run # this is a blocking call
requests.each do |r|
r.response.body
end
end
def em(urls, path = nil)
EventMachine.run do
multi = EventMachine::MultiRequest.new
urls.each_with_index do |url, i| multi.add("u#{i}".to_sym, EventMachine::HttpRequest.new(url).get) end
multi.callback do
multi.responses[:callback]
EventMachine.stop
end
end
end
def patron(urls, path=nil)
sess = Patron::Session.new
sess.timeout = 10
sess.base_url = "http://#{$server}"
sess.headers['User-Agent'] = 'Patron'
urls.each do |u|
resp = sess.get(u)
resp.body
end
end
$server ="127.0.0.1:8080"
i = 0
Small = (["http://#{$server}/4kb"] * 8).map { |u| "#{ u }?#{ i += 1 }" }
Big = (["http://#{$server}/6m"] * 8 ).map { |u| "#{ u }?#{ i += 1 }" }
SmallP = Small.map { |u| u.split(/http:\/\/#{$server}/).last }
BigP = Big.map { |u| u.split(/http:\/\/#{$server}/).last }
def check
fork do
50.times do
yield
end
memory_usage = `ps -o rss= -p #{Process.pid}`.to_i # in kilobytes
puts "\nMemory: #{ memory_usage }\n"
end
Process.wait
end
Benchmark.bm do |rep|
rep.report("4kb std") do check { std Small, "small_curb" } end
rep.report("4kb std_thr") do check { std_threaded Small, "small_curb" } end
rep.report("4kb patron") do check { patron SmallP, "small_curb" } end
rep.report("4kb curb") do check { curb Small, "small_curb" } end
rep.report("4kb em-http") do check { em Small, "small_em" } end
rep.report("4kb typhoeus") do check { typo Small, "small_typ" } end
rep.report("6m std") do check { std Big, "big_curb" } end
rep.report("6m std_thr") do check { std_threaded Big, "big_curb" } end
rep.report("6m patron") do check { patron BigP, "big_curb" } end
rep.report("6m curb") do check { curb Big, "big_curb" } end
rep.report("6m em-http") do check { em Big, "big_em" } end
rep.report("6m typhoeus") do check { typo Big, "big_typ" } end
rep.report("MIXED std") do check { std Small + Big, "mix_curb" } end
rep.report("MIXED std_thr") do check { std_threaded Small + Big, "mix_curb" } end
rep.report("MIXED patron") do check { patron SmallP + BigP, "mix_curb" } end
rep.report("MIXED curb") do check { curb Small + Big, "mix_curb" } end
rep.report("MIXED em-http") do check { em Small + Big, "mix_em" } end
rep.report("MIXED typhoeus") do check { typo Small + Big, "mix_typ" } end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment