[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Comparing two arrays



On Mon, Jul 24, 2000 at 12:57:08AM +0200, Marc Lehmann wrote:
> On Sun, Jul 23, 2000 at 05:18:16PM -0400, Jeff Pinyan <jeffp@crusoe.net> wrote:
> > Yup, I know.  Sadly, Perl doesn't optimize
> > 
> >   ($a,$b,$c) = (split)[-3 .. -1];
> 
> Just did a benchmark:
> 
> $x = ("555:66:77:88:99:100") x 100;
> 
> timethese 10000, {
>    a => q* @x = (split /:/, $x)[0..2] *,
>    b => q* @x = (split /:/, $x)[-3 .. -1] *,
> };
> 
> a:  6 wallclock secs ( 6.43 usr +  0.00 sys =  6.43 CPU) @ 1555.21/s (n=10000)
> b:  5 wallclock secs ( 6.44 usr +  0.00 sys =  6.44 CPU) @ 1552.80/s (n=10000)
> 
> At least for me, this means I don't care much ;)
> 
> (Yes, my regex was very simple).


If you were trying to observe the effects of optimization of split, try
this:


#!/usr/local/bin/perl

use Benchmark;

$x = ("555:66:77:88:99:100") x 100;

timethese 10000, {
   a => q* ($a, $b, $c) = (split /:/, $x)[0..2] *,
   b => q* ($a, $b, $c) = (split /:/, $x)[-3 .. -1] *,
   c => q* ($a, $b, $c) = (split /:/, $x) *,
};

__END__

Benchmark: timing 10000 iterations of a, b, c...
         a:  9 wallclock secs ( 8.33 usr +  0.02 sys =  8.35 CPU)
         b:  9 wallclock secs ( 8.33 usr +  0.02 sys =  8.35 CPU)
         c:  0 wallclock secs ( 0.25 usr +  0.00 sys =  0.25 CPU)
            (warning: too few iterations for a reliable count)


Ronald

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe