perl-embperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kee Hinckley <naz...@somewhere.com>
Subject Re: memory usage
Date Fri, 19 Dec 2003 15:53:36 GMT
At 1:44 PM +0100 12/19/03, Hans de Groot wrote:
>if I make a silly script like this:

Just so you know, that while is *real* inefficient.  What you really want is something like:
	s/foo.jpg/++$counter . ".jpg"/ge

See the below results.  I did them in 1 iteration and 10 separately because the while version
was too slow for me to wait for the results if I tried it 10 times.

Benchmark: timing 1 iterations of per-line g, slurp g, while data, while inline...
per-line g:  0 wallclock secs ( 0.14 usr +  0.00 sys =  0.14 CPU) @  7.14/s (n=1)
            (warning: too few iterations for a reliable count)
   slurp g:  0 wallclock secs ( 0.06 usr +  0.00 sys =  0.06 CPU) @ 16.67/s (n=1)
            (warning: too few iterations for a reliable count)
while data: 44 wallclock secs (35.37 usr +  0.00 sys = 35.37 CPU) @  0.03/s (n=1)
            (warning: too few iterations for a reliable count)
while inline: 44 wallclock secs (35.20 usr +  0.00 sys = 35.20 CPU) @  0.03/s (n=1)
            (warning: too few iterations for a reliable count)
               s/iter   while data while inline   per-line g      slurp g
while data       35.4           --          -0%        -100%        -100%
while inline     35.2           0%           --        -100%        -100%
per-line g      0.140       25164%       25043%           --         -57%
slurp g      6.00e-02       58850%       58567%         133%           --

at 10 iterations (with the slow two turned off)

Benchmark: timing 10 iterations of per-line g, slurp g, while data, while inline...
per-line g:  2 wallclock secs ( 1.41 usr +  0.00 sys =  1.41 CPU) @  7.09/s (n=10)
   slurp g:  1 wallclock secs ( 0.64 usr +  0.00 sys =  0.64 CPU) @ 15.62/s (n=10)
while data:  0 wallclock secs ( 0.00 usr +  0.00 sys =  0.00 CPU)
            (warning: too few iterations for a reliable count)
while inline:  0 wallclock secs ( 0.00 usr +  0.00 sys =  0.00 CPU)
            (warning: too few iterations for a reliable count)
                            Rate          per-line g            slurp g while data while inline
per-line g                7.09/s                  --               -55%      -100%       
-100%
slurp g                   15.6/s                120%                 --      -100%       
-100%
while data   10000000000000000/s 141000000000000000% 64000000000000016%         --       
   0%
while inline 10000000000000000/s 141000000000000000% 64000000000000016%         0%       
   --


#!/usr/bin/perl
#
use strict;
use warnings;

use Benchmark qw(cmpthese);

cmpthese($ARGV[0] || 10, {
        'while data'    => q{
                        return if ($ARGV[0] > 1);       # too slow
                        #print STDERR "while data: ";
                        my ($data, $counter);
                        $data = '';
                        open(T, "</etc/magic");
                        while (<T>) {
                            $data .= $_;
                        }
                        close(T);
                        $counter = 0;
                        while ($data =~ s/e/$counter/) { ++$counter; }
                        #print STDERR "$counter\n";
                    },
        'while inline'  => q{
                        return if ($ARGV[0] > 1);       # too slow
                        #print STDERR "while inline: ";
                        my ($data, $counter);
                        $counter = 0;
                        open(T, "</etc/magic");
                        while (<T>) {
                            while (s/e/$counter/) { ++$counter; }
                        }
                        close(T);
                        #print STDERR "$counter\n";
                    },
        'per-line g'    => q{
                        #print STDERR "per-line g: ";
                        my ($data, $counter);
                        $counter = 0;
                        open(T, "</etc/magic");
                        while (<T>) {
                            s/e/++$counter/ge;
                        }
                        close(T);
                        #print STDERR "$counter\n";
                    },
        'slurp g'       => q{
                        #print STDERR "slurp g: ";
                        my ($data, $counter);
                        $counter = 0;
                        open(T, "</etc/magic");
                        select((select(T), $/ = undef)[0]);     # no eol
                        $data = <T>;
                        close(T);
                        $data =~ s/e/++$counter/ge;
                        #print STDERR "$counter\n";
                    },
        });

-- 
Kee Hinckley
http://www.messagefire.com/         Next Generation Spam Defense
http://commons.somewhere.com/buzz/  Writings on Technology and Society

I'm not sure which upsets me more: that people are so unwilling to accept
responsibility for their own actions, or that they are so eager to regulate
everyone else's.

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Mime
View raw message