Last active
January 3, 2016 23:39
-
-
Save hakanensari/8536834 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 './lib/excon' | |
include Excon | |
uris = { | |
'Good URI' => "http://example.org/#{'foo/' * 10}?#{10.times.map { 'bar=baz' }.join('&')}", | |
'Bad URI' => "http://example.org/#{'foo /' * 10}?#{10.times.map { 'bar=baz' }.join('&')}" | |
} | |
uris.each do |desc, uri| | |
puts desc | |
Benchmark.bm(7) do |x| | |
x.report('force') { 10000.times { Utils.escape_uri(Utils.unescape_uri(uri)) } } | |
x.report('check') { 10000.times { uri.include?('%') ? uri : Utils.escape_uri(uri) } } | |
x.report('nop') { 10000.times { uri } } | |
end | |
end | |
# Good URI | |
# user system total real | |
# force 0.030000 0.000000 0.030000 ( 0.033123) | |
# check 0.020000 0.000000 0.020000 ( 0.017557) | |
# nop 0.000000 0.000000 0.000000 ( 0.000467) | |
# Bad URI | |
# user system total real | |
# force 0.260000 0.000000 0.260000 ( 0.255536) | |
# check 0.230000 0.000000 0.230000 ( 0.232057) | |
# nop 0.000000 0.000000 0.000000 ( 0.000465) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment