in reply to list of scalars vs arrays, speed?

Well, I doubt its brilliant but I believe I can venture a hypothesis:

The scalar version allows perl more opportunities to optimize. For instance it will know at compile time how many elements to copy from the right hand side and it will not have to dynamically allocate space for the target array at run time. Also it will not have to do basic administrative details like emptying the target array before refilling it, in the case of the scalars it need only copy the value or undef the var.

There are probably other less obvious optimizations that Perl can do at compile time with the scalars but must do at run time with the array.

BTW: Next time you might consider writing your killer scalar sub a bit differently:

my $sub=eval 'sub {('.join(',',map{'$s'.$_}0..1000).')=@base}';
:-)

Yves / DeMerphq
---
Writing a good benchmark isnt as easy as it might look.

Replies are listed 'Best First'.
Re: Re: list of scalars vs arrays, speed?
by BUU (Prior) on May 02, 2002 at 12:44 UTC
    ... I knew i was missing something there. I forgot about doing it before the test.. I didnt originally use eval because i didnt want to add the over head of an eval in my time these loops.