Skip to content

Instantly share code, notes, and snippets.

@kogent
Forked from lifo/bench.rb
Created July 2, 2009 04:45
Show Gist options
  • Save kogent/139272 to your computer and use it in GitHub Desktop.
Save kogent/139272 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'curb'
require "net/http"
require 'benchmark'
# http://0.0.0.0:8080
#
# class HomeController < ApplicationController
# def index
# sleep 3
# end
# end
# [lifo@null curb (master)]£ ruby bench.rb
# Curl::Multi 3.01691508293152
# Net::HTTP 15.0276219844818
responses = {}
curb = Benchmark.realtime do
m = Curl::Multi.new
5.times do |i|
responses[i] = ""
c = Curl::Easy.new('http://0.0.0.0:8080') do |curl|
curl.follow_location = false
curl.on_body{|data| responses[i] << data; data.size }
end
m.add(c)
end
m.perform
end
puts "Curl::Multi #{curb}"
nh = Benchmark.realtime do
5.times do
http = Net::HTTP.start('0.0.0.0', 8080)
res = http.request(Net::HTTP::Get.new("/"))
end
end
puts "Net::HTTP #{nh}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment