You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Torsten Förtsch <to...@gmx.net> on 2011/03/29 18:52:23 UTC
Linux::Smaps
Hi,
after having been told by Ævar that Linux::Smaps is really slow I tuned it a
bit. Here is what I get. "new" is version 0.07, "old" is 0.06:
perl -MBenchmark=:all,:hireswallclock -MData::Dumper -e '
sub tm {
my ($title)=@_;
if( my $pid=open my $fh, "-|" ) {
local $/;
my $s=readline $fh;
$s=~s/\A(.+\n)//;
print $1;
my $VAR1;
return eval $s;
} else {
require Linux::Smaps;
print Dumper +timethis -20, sub {Linux::Smaps->new->all}, $title;
exit 0;
}
}
my %res=(old=>tm "old");
unshift @INC, "lib";
$res{new}=tm "new"; cmpthese \%res
'
old: 20.9829 wallclock secs (20.49 usr + 0.45 sys = 20.94 CPU) @ 70.87/s (n=1484)
new: 21.0381 wallclock secs (19.09 usr + 1.92 sys = 21.01 CPU) @ 322.42/s (n=6774)
Rate old new
old 70.9/s -- -78%
new 322/s 355% --
Meanwhile Ævar uploaded his own quite specialized smaps parser
(Linux::Smaps::Tiny) to CPAN. Here is what I get in comparison:
perl -Ilib -MLinux::Smaps -MLinux::Smaps::Tiny \
-MBenchmark=:all,:hireswallclock -e '
cmpthese timethese -5, {
tiny=>sub{Linux::Smaps::Tiny::get_smaps_summary},
smaps=>sub{scalar Linux::Smaps->new->all}
}
'
Benchmark: running smaps, tiny for at least 5 CPU seconds...
smaps: 5.0982 wallclock secs ( 4.56 usr + 0.47 sys = 5.03 CPU) @ 365.81/s (n=1840)
tiny: 5.51047 wallclock secs ( 4.63 usr + 0.83 sys = 5.46 CPU) @ 591.58/s (n=3230)
Rate smaps tiny
smaps 366/s -- -38%
tiny 592/s 62% --
Torsten Förtsch
--
Need professional modperl support? Hire me! (http://foertsch.name)
Like fantasy? http://kabatinte.net
Re: Linux::Smaps
Posted by Ævar Arnfjörð Bjarmason <av...@gmail.com>.
On Tue, Mar 29, 2011 at 18:52, Torsten Förtsch <to...@gmx.net> wrote:
> Meanwhile Ævar uploaded his own quite specialized smaps parser
> (Linux::Smaps::Tiny) to CPAN. Here is what I get in comparison:
>
> perl -Ilib -MLinux::Smaps -MLinux::Smaps::Tiny \
> -MBenchmark=:all,:hireswallclock -e '
> cmpthese timethese -5, {
> tiny=>sub{Linux::Smaps::Tiny::get_smaps_summary},
> smaps=>sub{scalar Linux::Smaps->new->all}
> }
> '
> Benchmark: running smaps, tiny for at least 5 CPU seconds...
> smaps: 5.0982 wallclock secs ( 4.56 usr + 0.47 sys = 5.03 CPU) @ 365.81/s (n=1840)
> tiny: 5.51047 wallclock secs ( 4.63 usr + 0.83 sys = 5.46 CPU) @ 591.58/s (n=3230)
> Rate smaps tiny
> smaps 366/s -- -38%
> tiny 592/s 62% --
I've just uploaded 0.06 of Linux::Smaps::Tiny. It'll use C XS code to
parse the file by default, falling back to the pure-perl version if
there's no compiler on the system:
$ perl -Ilib -MLinux::Smaps -MLinux::Smaps::Tiny
-MLinux::Smaps::Tiny::PP -MBenchmark=:all,:hireswallclock -e '
cmpthese timethese -5, {
tiny=>sub{Linux::Smaps::Tiny::get_smaps_summary},
tiny_pp=>sub{Linux::Smaps::Tiny::PP::__get_smaps_summary},
smaps=>sub{scalar Linux::Smaps->new->all}
}
'
Benchmark: running smaps, tiny, tiny_pp for at least 5 CPU seconds...
smaps: 5.3729 wallclock secs ( 4.42 usr + 0.93 sys = 5.35
CPU) @ 792.52/s (n=4240)
tiny: 5.42358 wallclock secs ( 2.94 usr + 2.46 sys = 5.40
CPU) @ 2082.59/s (n=11246)
tiny_pp: 5.39001 wallclock secs ( 4.02 usr + 1.36 sys = 5.38
CPU) @ 1029.18/s (n=5537)
Rate smaps tiny_pp tiny
smaps 793/s -- -23% -62%
tiny_pp 1029/s 30% -- -51%
tiny 2083/s 163% 102% --