Linux::Smaps
am 29.03.2011 18:52:23 von torsten.foertschHi,
after having been told by =C6var that Linux::Smaps is really slow I tuned i=
t a
bit. Here is what I get. "new" is version 0.07, "old" is 0.06:
perl -MBenchmark=3D:all,:hireswallclock -MData::Dumper -e '
sub tm {
my ($title)=3D@_;
if( my $pid=3Dopen my $fh, "-|" ) {
local $/;
my $s=3Dreadline $fh;
$s=3D~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=3D(old=3D>tm "old");
unshift @INC, "lib";
$res{new}=3Dtm "new"; cmpthese \%res
'
old: 20.9829 wallclock secs (20.49 usr + 0.45 sys =3D 20.94 CPU) @ =
70.87/s (n=3D1484)
new: 21.0381 wallclock secs (19.09 usr + 1.92 sys =3D 21.01 CPU) @ =
322.42/s (n=3D6774)
Rate old new
old 70.9/s -- -78%
new 322/s 355% --
Meanwhile =C6var 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=3D:all,:hireswallclock -e '
cmpthese timethese -5, {
tiny=3D>sub{Linux::Smaps::Tiny::get_smaps_summary},
smaps=3D>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 =3D 5.03 CPU) @ 3=
65.81/s (n=3D1840)
tiny: 5.51047 wallclock secs ( 4.63 usr + 0.83 sys =3D 5.46 CPU) @ =
591.58/s (n=3D3230)
Rate smaps tiny
smaps 366/s -- -38%
tiny 592/s 62% --
Torsten Förtsch
=2D-=20
Need professional modperl support? Hire me! (http://foertsch.name)
Like fantasy? http://kabatinte.net