Return-Path: Delivered-To: apmail-perl-embperl-archive@www.apache.org Received: (qmail 32129 invoked from network); 19 Dec 2003 15:53:50 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 19 Dec 2003 15:53:50 -0000 Received: (qmail 29072 invoked by uid 500); 19 Dec 2003 15:53:43 -0000 Delivered-To: apmail-perl-embperl-archive@perl.apache.org Received: (qmail 29058 invoked by uid 500); 19 Dec 2003 15:53:43 -0000 Mailing-List: contact embperl-help@perl.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Delivered-To: mailing list embperl@perl.apache.org Received: (qmail 29040 invoked from network); 19 Dec 2003 15:53:43 -0000 Received: from unknown (HELO somewhere.com) (66.92.72.194) by daedalus.apache.org with SMTP; 19 Dec 2003 15:53:43 -0000 Received: from [66.92.72.194] (account nazgul HELO [192.168.1.104]) by somewhere.com (CommuniGate Pro SMTP 4.1.5) with ESMTP-TLS id 3367314; Fri, 19 Dec 2003 10:53:45 -0500 Mime-Version: 1.0 X-Sender: nazgul@somewhere.com@pop.messagefire.com Message-Id: In-Reply-To: <1071837861.3ff85c9b3079b@webmail.dandy.nl> References: <1071755311.30202bd8ecb3a@webmail.dandy.nl> <0bbe01c3c5ec$cc0577d0$f90b0b0a@wingr2> <1071837861.3ff85c9b3079b@webmail.dandy.nl> Date: Fri, 19 Dec 2003 10:53:36 -0500 To: Hans de Groot From: Kee Hinckley Subject: Re: memory usage Cc: embperl@perl.apache.org Content-Type: text/plain; charset="us-ascii" X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N 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, ") { $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, ") { 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, ") { s/e/++$counter/ge; } close(T); #print STDERR "$counter\n"; }, 'slurp g' => q{ #print STDERR "slurp g: "; my ($data, $counter); $counter = 0; open(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