Skip to content

Instantly share code, notes, and snippets.

@xaicron
Created January 8, 2013 10: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 xaicron/4482790 to your computer and use it in GitHub Desktop.
Save xaicron/4482790 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
package Plack::Request::URIClone;
use parent 'Plack::Request';
sub uri {
my $self = shift;
$self->{_uri} ||= $self->SUPER::uri();
$self->{_uri}->clone;
}
package Plack::Request::DataClone;
use Data::Clone;
use parent 'Plack::Request';
sub uri {
my $self = shift;
$self->{_uri} ||= $self->SUPER::uri();
clone($self->{_uri});
}
package main;
use strict;
use warnings;
use Benchmark qw(:hireswallclock cmpthese);
use HTTP::Request;
use HTTP::Message::PSGI;
use Plack::Request;
my $http_req = HTTP::Request->new(GET => 'http://mattn.org/?ossan=4000YEN');
my $uri_clone = Plack::Request::URIClone->new($http_req->to_psgi);
my $data_clone = Plack::Request::DataClone->new($http_req->to_psgi);
my $plain = Plack::Request->new($http_req->to_psgi);
cmpthese -1, {
uri_clone => sub {
$uri_clone->uri;
},
data_clone => sub {
$data_clone->uri;
},
plain => sub {
$plain->uri;
},
};
__END__
Rate plain data_clone uri_clone
plain 7450/s -- -95% -96%
data_clone 160627/s 2056% -- -17%
uri_clone 193730/s 2500% 21% --
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment