Skip to content

Instantly share code, notes, and snippets.

@creaktive
Created May 30, 2014 16:36
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 creaktive/9c43b4729fa0df859765 to your computer and use it in GitHub Desktop.
Save creaktive/9c43b4729fa0df859765 to your computer and use it in GitHub Desktop.
Benchmark URI escape/unescape provided by Net::Curl::Easy, URI::Escape & URI::Escape::XS
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use Benchmark::Dumb qw(cmpthese);
use Net::Curl::Easy;
use URI::Escape;
use URI::Escape::XS;
my $curl = Net::Curl::Easy->new;
my $raw = "10% is enough\n";
my $escaped = '10%25%20is%20enough%0A';
cmpthese(1000.01 => {
curl_escape => sub {
$curl->escape($raw);
},
uri_escape => sub {
URI::Escape::uri_escape($raw);
},
uri_escape_xs => sub {
URI::Escape::XS::uri_escape($raw);
},
curl_unescape => sub {
$curl->unescape($escaped);
},
uri_unescape => sub {
URI::Escape::uri_unescape($escaped);
},
uri_unescape_xs => sub {
URI::Escape::XS::uri_unescape($escaped);
},
});
__DATA__
Rate uri_escape uri_unescape curl_escape uri_escape_xs uri_unescape_xs curl_unescape
uri_escape 135181+-8.6/s -- -37.6% -81.4% -84.7% -88.2% -88.9%
uri_unescape 216526+-44/s 60.2% -- -70.1% -75.5% -81.1% -82.2%
curl_escape 724990+-390/s 436.3% 234.8% -- -17.9% -36.7% -40.3%
uri_escape_xs 882800+-1100/s 553.06+-0.84% 307.72+-0.53% 21.77+-0.17% -- -22.9% -27.3%
uri_unescape_xs 1.14545e+06+-4.3/s 747.3% 429.0% 58.0% 29.75+-0.17% -- -5.7%
curl_unescape 1.21422e+06+-340/s 798.2% 460.8% 67.48+-0.1% 37.54+-0.18% 6.0% --
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment