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

Re: [FWP] Perl Card Games



Larry Rosler wrote:
> 
> >       @a = (undef) x 5;  # any value; it will get overwritten.
> 
> I keep seeing that, and I keep wondering how that differs from this:
> 
>       my @a; $#a = 4;
> 
> Enlightenment, please?

It's slower?  Otherwise, I'd expect there to be no difference (barring
use of deprecated $[).

use strict;
use Benchmark;

timethese 10000, {
    Undef5    => sub { my @a; @a = (undef) x 5 },
    Size5     => sub { my @a; $#a = 4 },
    Undef50   => sub { my @a; @a = (undef) x 50 },
    Size50    => sub { my @a; $#a = 49 },
    Undef500  => sub { my @a; @a = (undef) x 500 },
    Size500   => sub { my @a; $#a = 499 },
    Undef5000 => sub { my @a; @a = (undef) x 5000 },
    Size5000  => sub { my @a; $#a = 4999 },
};

__END__
Benchmark: timing 10000 iterations of Size5, Size50, Size500, Size5000,
Undef5, Undef50, Undef500, Undef5000...
     Size5:  0 wallclock secs ( 0.11 usr +  0.00 sys =  0.11 CPU)
            (warning: too few iterations for a reliable count)
    Size50:  1 wallclock secs ( 0.15 usr +  0.00 sys =  0.15 CPU)
            (warning: too few iterations for a reliable count)
   Size500:  0 wallclock secs ( 0.63 usr +  0.00 sys =  0.63 CPU)
  Size5000:  6 wallclock secs ( 6.05 usr +  0.00 sys =  6.05 CPU)
    Undef5:  1 wallclock secs ( 0.21 usr +  0.00 sys =  0.21 CPU)
            (warning: too few iterations for a reliable count)
   Undef50:  1 wallclock secs ( 0.87 usr +  0.00 sys =  0.87 CPU)
  Undef500:  7 wallclock secs ( 7.50 usr +  0.00 sys =  7.50 CPU)
 Undef5000: 86 wallclock secs (82.85 usr +  0.01 sys = 82.86 CPU)

-- 
Rick Delaney
rick.delaney@home.com

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