Linux::Smaps

Linux::Smaps

am 29.03.2011 18:52:23 von torsten.foertsch

Hi,

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

Re: Linux::Smaps

am 03.04.2011 21:30:18 von avarab

On Tue, Mar 29, 2011 at 18:52, Torsten Förtsch et> 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=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) @ 365.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%    --

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=3D:all,:hireswallclock -e '
cmpthese timethese -5, {
tiny=3D>sub{Linux::Smaps::Tiny::get_smaps_summary},
tiny_pp=3D>sub{Linux::Smaps::Tiny::PP::__get_smaps_summary},
smaps=3D>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 =3D 5.35
CPU) @ 792.52/s (n=3D4240)
tiny: 5.42358 wallclock secs ( 2.94 usr + 2.46 sys =3D 5.40
CPU) @ 2082.59/s (n=3D11246)
tiny_pp: 5.39001 wallclock secs ( 4.02 usr + 1.36 sys =3D 5.38
CPU) @ 1029.18/s (n=3D5537)
Rate smaps tiny_pp tiny
smaps 793/s -- -23% -62%
tiny_pp 1029/s 30% -- -51%
tiny 2083/s 163% 102% --