Created
April 14, 2010 03:48
-
-
Save bhb/365430 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 'benchmark' | |
require 'typhoeus' | |
require 'yajl' | |
require 'json' | |
require 'yaml' | |
require 'ruby-debug' | |
require 'uri' | |
require 'yajl/http_stream' | |
hash = {:a => 1} | |
base_uri = "http://api.devver.net/projects/git%3A%2F%2Fgithub.com%2Fsinatra%2Fsinatra.git/revisions/" | |
shas = ["186a5bc9b66ac163e4f74a88c3406a1587d97eae", "e49365f1cd7299a3a63fea7594943acd1f289322", "79a99939167b039bc740d693eb25a4ed09b37b52", "1b8fda825e9cda5f44b26684119b19a49c2e416b", "f942ad76589d649b66458efe61648f13a08ef8a0", "e153415527c903191ae64cb5965fc33cb30b1a7a", "3cfd06ad86ca8febf339037e37c6765572c89f42", "849a5a95fc33e6ddd3633863c4bc3ee0065c503a", "15651d9ee14270048b511ab535287d3ddc965ad7", "30c2ef839649dc3b124672854d32a34b88b52501", "0915274b6959a4130517dd1c1b5790df4f200e9e", "171bf43341cd0f71c87299740876a25a9a58266b", "3ea36c94cf5f65d5d3244df07c384a2e70647853", "ceac46f0bc129a6e994a06100aa854f606fe5992", "035fe4705d54590b5477faeee1c9cd96a63fcc8d", "2723d7ec3b192d720fc4ae2d53c48fea4dd71dce", "ae34a6fde5e15e9ba3ca40cf800d0366e44eec1f", "19efdf869984071b801d02795ed70d5e31aa3e62", "f5efc370c8450a8b1308a3a87f743fe8b25e5097", "b6701db3faf1fba0bb5675e8a78385b618280fb2", "ccb66b0f3096773599fcff93925865c788d98d34", "8a7dd92e1c1b94ac1beeafda5af8898384a02f00", "e1638a43ad3a5c5ea70db56944a5230cc86e537a", "c496254f2be3d27bba238bf78c1c7376976eb924", "794437e921c8bbafd106aa99819af69293e61574", "e2c73bf1b036adb31853b2c92909eb447876d233", "11e1f8a971ce2e40d544815d359ee19dace48f4c", "7526dacf33d4411d7f0e98bceeadc91b46dc56bb", "7882efdf0bf24055f11be52a326f25efababc67b", "37eb3a767f6697241fa15c8f4edfd0f9a63d2f70"] | |
# change this to 5 to get an idea of perf difference for SHAs just on a dashboard graph | |
shas = shas[0,30] | |
URLS = shas.map { |sha| base_uri+sha+"/raw_metrics"} | |
def make_typhoeus_requests(accept_type, &block) | |
hydra = Typhoeus::Hydra.new(:max_concurrency => 5) | |
URLS.each do |url| | |
request = Typhoeus::Request.new(url, :headers => {:Accept => accept_type}) | |
request.on_complete(&block) | |
hydra.queue request | |
end | |
hydra.run | |
end | |
metrics = [] | |
Benchmark.bmbm(25) do |bm| | |
bm.report('typhoeus yaml') do | |
metrics[0] = [] | |
make_typhoeus_requests('text/x-yaml') do |response| | |
metrics[0] << YAML.load(response.body) | |
end | |
end | |
bm.report('typhoeus json') do | |
metrics[1] = [] | |
make_typhoeus_requests('application/json') do |response| | |
metrics[1] << JSON.parse(response.body) | |
end | |
end | |
bm.report('typhoeus yajl') do | |
metrics[2] = [] | |
make_typhoeus_requests('application/json') do |response| | |
metrics[2] << Yajl::Parser.parse(response.body) | |
end | |
end | |
# bm.report('streaming yajl') do | |
# metrics[3] = [] | |
# URLS.each do |url| | |
# metrics[3] << Yajl::HttpStream.get(URI.parse(url)) | |
# end | |
# end | |
end | |
def noop | |
end | |
# This is intended to make sure we're not comparing the case where YAML is getting real data | |
# but JSON is getting an empty hash for some reason | |
# A few discrepancies may show up because some cached data in the real API has 'rails_best_practices' | |
# (for the YAML representation) while the JSON does not | |
metrics.each_index do |i| | |
next if i+1 == metrics.length | |
metrics[0].length.times do |j| | |
if metrics[i][j].keys.map{|x|x.to_s}.sort == metrics[i+i][j].keys.map{|x|x.to_s}.sort | |
#puts 'same' | |
else | |
puts "difference between #{i} and #{i+i} on #{shas[j]}" | |
noop | |
end | |
end | |
end | |
puts 'done' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment