Permalink
Browse files

Updated POD. Added a benchmark script

  • Loading branch information...
mithun committed Mar 19, 2012
1 parent d8b0c99 commit daf8c379fb0c0e75cd903141d9b52560b90ad861
Showing with 97 additions and 3 deletions.
  1. +85 −0 .author/benchmark.pl
  2. +1 −0 Build.PL
  3. +2 −1 MANIFEST.SKIP
  4. +4 −1 changes.mkdn
  5. +5 −1 lib/URI/Encode.pm
View
@@ -0,0 +1,85 @@
+#!/usr/bin/perl
+
+####################
+# LOAD CORE MODULES
+####################
+use strict;
+use warnings FATAL => 'all';
+
+# Autoflush ON
+local $| = 1;
+
+####################
+# LOAD MODULES
+####################
+use URI::Encode;
+use URI::Escape qw();
+use URI::Escape::XS qw();
+use Benchmark qw(cmpthese);
+
+####################
+# SETTINGS
+####################
+
+my $num_of_iters = '1000000';
+my $url = 'http://www.google.com/search?q=Ingy döt Net';
+
+# Objects
+my $obj_uri_encode = URI::Encode->new();
+
+# Reserved characters
+my $reserved_re = "^a-zA-Z0-9\-\_\.\~\!\*\'\(\)\;\:\@\&\=\+\$\,\/\?\%\#\[\]";
+
+print "Encoding URL: $url\n";
+print "Using URI::Escape ($URI::Escape::VERSION)\t-> "
+ . URI::Escape::uri_escape_utf8( $url, $reserved_re ) . "\n";
+print "Using URI::Escape::XS ($URI::Escape::XS::VERSION)\t-> "
+ . URI::Escape::XS::uri_escape( $url, $reserved_re ) . "\n";
+print "Using URI::Encode ($URI::Encode::VERSION)\t-> "
+ . $obj_uri_encode->encode($url) . "\n";
+
+####################
+# RUN BENCH
+####################
+print "\n\nBenchmarking $num_of_iters iterations on Perl $] ($^O)\n\n";
+
+cmpthese(
+ $num_of_iters,
+ {
+ 'URI::Escape' => sub {
+ URI::Escape::uri_escape_utf8( $url, $reserved_re );
+ },
+ 'URI::Escape::XS' => sub {
+ URI::Escape::XS::uri_escape( $url, $reserved_re );
+ },
+ 'URI::Encode' => sub { $obj_uri_encode->encode($url) },
+ }
+);
+
+print "\n";
+
+####################
+# DONE
+####################
+exit 0;
+
+__END__
+
+=pod
+
+Sample script output
+
+ Encoding URL: http://www.google.com/search?q=Ingy döt Net
+ Using URI::Escape (3.31) -> http://www.google.com/search?q=Ingy döt Net
+ Using URI::Escape::XS (0.08)-> http://www.google.com/search?q=Ingy döt Net
+ Using URI::Encode (0.06) -> http://www.google.com/search?q=Ingy%20d%C3%83%C2%B6t%20Net
+
+
+ Benchmarking 1000000 iterations on Perl 5.012003 (darwin)
+
+ Rate URI::Encode URI::Escape URI::Escape::XS
+ URI::Encode 61237/s -- -87% -91%
+ URI::Escape 473934/s 674% -- -29%
+ URI::Escape::XS 671141/s 996% 42% --
+
+=cut
View
@@ -31,6 +31,7 @@ my $builder = Module::Build->new(
create_license => 1,
create_makefile_pl => 'traditional',
meta_merge => {
+ keywords => [qw(uri escape encode percent)],
resources => {
bugtracker =>
'http://rt.cpan.org/Public/Dist/Display.html?Name=URI-Encode',
View
@@ -8,4 +8,5 @@
\.DS_Store$
^MYMETA.yml$
^MYMETA\.json$
-\.mkdn$
+\.mkdn$
+^\.author
View
@@ -1,7 +1,10 @@
% Version History for URI-Encode
% Mithun Ayachit
----------------------
+# 0.061
+
+- POD updates
+- Added a benchmark script
# 0.06
View
@@ -12,7 +12,7 @@ use Carp qw(croak carp);
#######################
# VERSION
#######################
-our $VERSION = '0.06';
+our $VERSION = '0.061';
#######################
# EXPORT
@@ -155,9 +155,13 @@ to encode strings (mainly URLs) into a format which can be pasted into a plain
text emails, and that those links are 'click-able' by the person reading that
email. This can be accomplished by NOT encoding the reserved characters.
+This module can also be useful when using L<HTTP::Tiny> to ensure the URLs are properly escaped.
+
If you are looking for speed and want to encode reserved characters, use
L<URI::Escape::XS>
+See L<this script|https://github.com/mithun/perl-uri-encode/raw/master/.author/benchmark.pl> for a comparison on encoding results and performance.
+
=head1 METHODS
=head2 new()

0 comments on commit daf8c37

Please sign in to comment.