in reply to list of scalars vs arrays, speed?

It seems likely to me that the first one's slow performance is because it has to first extend the @s array because it's initially empty. It then has to copy over all the values into newly created scalars in the array. Whereas when you're just copying into scalars, the scalars are just there and already exist, so no extending, just a matter of sv_setsv() internally.

The second test gains because the overhead of the large number of values overwhelms the extending delay.

Replies are listed 'Best First'.
Re: Re: list of scalars vs arrays, speed?
by pdcawley (Hermit) on May 02, 2002 at 09:22 UTC
    If I add a couple of tests where, instead of messing with globals you use lexical variables (just stick a 'my' at the front of each sub), I get the following results from a cmpthese(-10,{...}) run. I've combined the two sizes of test, hopefully the table is self explanatory.
                  Rate $ 1000 @ 1000 my $ 1000 my @ 1000 my @ 5    @ 5 my $ 5    $ 5
    $ 1000      1192/s     --   -15%      -15%      -22%   -99%   -99%  -100%  -100%
    @ 1000      1399/s    17%     --       -1%       -8%   -99%   -99%  -100%  -100%
    my $ 1000   1408/s    18%     1%        --       -8%   -99%   -99%  -100%  -100%
    my @ 1000   1528/s    28%     9%        8%        --   -99%   -99%  -100%  -100%
    my @ 5    126214/s 10492%  8921%     8861%     8162%     --   -34%   -60%   -63%
    @ 5       191633/s 15981% 13596%    13506%    12445%    52%     --   -40%   -44%
    my $ 5    317943/s 26581% 22624%    22474%    20713%   152%    66%     --    -7%
    $ 5       341012/s 28517% 24273%    24111%    22224%   170%    78%     7%     --
    
    Hmm... I do like the way the 1000s are almost the reverse of the 5s. Life's too short to go generating a graph to find out where the crossover points are, but it's certainly odd...