Created
December 4, 2014 22:16
-
-
Save aj0strow/699012f8014793190585 to your computer and use it in GitHub Desktop.
ruby curl benchmark
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 'dotenv' | |
Dotenv.load | |
require 'benchmark' | |
require 'multi_json' | |
require 'firebase' | |
require 'patron' | |
Benchmark.bmbm do |x| | |
x.report('curl ') do | |
cmd = 'curl -s -o /dev/null -X PUT' | |
cmd += %( -H 'Accept:application/json') | |
cmd += %( -H 'Content-Type:application/json') | |
cmd += %( -d '{ "test": 1 }') | |
cmd += " #{ ENV['FIREBASE_URL'] }/benchmark/curl.json" | |
cmd += "?auth=#{ ENV['FIREBASE_SECRET'] }" | |
system cmd | |
end | |
x.report('firebase gem') do | |
firebase = Firebase::Client.new(ENV['FIREBASE_URL'], ENV['FIREBASE_SECRET']) | |
response = firebase.set('benchmark/gem', { test: 1 }) | |
(200..204).include?(response.code) | |
end | |
x.report('patron ') do | |
sess = Patron::Session.new | |
sess.timeout = 10 | |
sess.base_url = ENV['FIREBASE_URL'] | |
sess.headers['Accept'] = 'application/json' | |
sess.headers['Content-Type'] = 'application/json' | |
url = "/benchmark/patron.json?auth=#{ ENV['FIREBASE_SECRET'] }" | |
response = sess.put(url, { test: 1 }.to_json) | |
(200..204).include?(response.status) | |
end | |
end | |
__END__ | |
$ ruby bench.rb | |
Rehearsal ------------------------------------------------ | |
curl 0.000000 0.000000 0.050000 ( 0.367531) | |
firebase gem 0.030000 0.010000 0.040000 ( 2.473376) | |
patron 0.010000 0.000000 0.010000 ( 0.485663) | |
--------------------------------------- total: 0.100000sec | |
user system total real | |
curl 0.000000 0.000000 0.040000 ( 0.359838) | |
firebase gem 0.010000 0.010000 0.020000 (120.477957) | |
patron 0.010000 0.000000 0.010000 ( 0.421187) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment