Subject: | Use Storable::dclone for HTTP::Headers::clone |
It seems that the HTTP::Response::clone method is slower than
Storable::dclone. So my suggestion is to use Storable::dclone instead of
HTTP::Response::clone if Storable is available or a global variable
instructs HTTP::Response to do so.
Attached is a benchmark script.
Regards,
Slaven
Subject: | bla20.pl |
#!/usr/bin/perl
use strict;
use warnings;
no warnings 'redefine';
use Benchmark qw(cmpthese);
use HTTP::Response;
use HTTP::Headers;
use Storable qw(dclone);
use Test::More 'no_plan';
use YAML::Syck;
my $http_headers = YAML::Syck::Load(<<EOF);
--- !!perl/hash:HTTP::Headers
accept-ranges: bytes
client-date: Thu, 25 Sep 2008 13:10:21 GMT
client-peer: 172.17.30.1:84
client-response-num: 10
content-length: 4122
content-type: image/jpeg
date: Thu, 25 Sep 2008 13:10:21 GMT
etag: '"1746eb-101a-b09afc40"'
last-modified: Thu, 18 Sep 2008 13:37:45 GMT
server: Apache/2.2.3 (Debian) PHP/5.2.5-3 with Suhosin-Patch mod_perl/2.0.3 Perl/v5.8.8
EOF
# cmpthese(-1, {
# using_http_response_clone => sub {
# HTTP::Response->new(undef, undef, $http_headers);
# },
# using_storable_clone => sub {
# local *HTTP::Headers::clone = sub { dclone shift };
# HTTP::Response->new(undef, undef, $http_headers);
# },
# }
# );
my $res1;
my $res2;
cmpthese(-1, {
http_response_clone => sub {
$res1 = $http_headers->clone;
},
using_storable_clone => sub {
local *HTTP::Headers::clone = sub { dclone shift };
$res2 = dclone $http_headers;
},
}
);
is_deeply($res2, $res1);
__END__
Rate http_response_clone using_storable_clone
http_response_clone 5440/s -- -64%
using_storable_clone 15175/s 179% --
ok 1
1..1