Skip to content

Instantly share code, notes, and snippets.

@hakanensari
Last active January 3, 2016 23:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hakanensari/8536834 to your computer and use it in GitHub Desktop.
Save hakanensari/8536834 to your computer and use it in GitHub Desktop.
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