This post originated from an RSS feed registered with Ruby Buzz
by Eric Hodel.
Original Post: curb 0.7.3 performs as expected
Feed Title: Segment7
Feed URL: http://blog.segment7.net/articles.rss
Feed Description: Posts about and around Ruby, MetaRuby, ruby2c, ZenTest and work at The Robot Co-op.
Over loopback, curb runs about 2.4x the speed of net-http-persistent. This is the performance I expected curb to give. Having a pure-ruby library perform 2.4x worse than a C library makes net/http a fantastic library.
Remember, this benchmark and the previous one were designed to model a web-service type workload where many small requests are made. These benchmarks aren't designed to model downloading large files.
require 'rubygems'
require 'benchmark'
require 'net/http/persistent'
require 'curb'
# dd if=/dev/zero of=~/Sites/zeros-1k bs=1024 c=1
uri_1k = URI.parse 'http://localhost/~drbrain/zeros-1k'
uri_2k = URI.parse 'http://localhost/~drbrain/zeros-2k'
uri_10k = URI.parse 'http://localhost/~drbrain/zeros-10k'
uri = uri_2k
N = 100_000
Benchmark.bmbm do |bm|
bm.report 'Net::HTTP::Persistent' do
http_p = Net::HTTP::Persistent.new
N.times do
response = http_p.request uri
response.body
end
end
bm.report 'curb' do
curl = Curl::Easy.new
url = uri.to_s
N.times do
curl.url = url
curl.perform
curl.body_str
end
end
end
Rehearsal ---------------------------------------------------------
Net::HTTP::Persistent 54.070000 3.930000 58.000000 ( 71.651048)
curb 11.800000 4.510000 16.310000 ( 30.930453)
----------------------------------------------- total: 74.310000sec
user system total real
Net::HTTP::Persistent 54.130000 3.930000 58.060000 ( 72.430575)
curb 11.860000 4.540000 16.400000 ( 30.804222)