http://www.perlmonks.org?node_id=574843


in reply to Re^2: Linked lists as arrays: inserting values
in thread Linked lists as arrays: inserting values

Running your code on my Linux box, I get:
qwurx [shmem] ~> perl 574821.pl 6000 7000 10000 Array size: 10000 Inserting: 6000 .. 7000 Rate splicing radiant splicing 46.8/s -- -66% radiant 137/s 193% --

You are inserting a number between 6000 and 7000 at index 1, in every call to insert1 and insert2.

# called as insert1( \@ary, 1, $_ ) for $START .. $END sub insert1 { my ( $ra, $index, $elem ) = @_; @$ra = @$ra[0 .. $index-1], $elem, @$ra[$index .. @$ra-1]; } # I tested with sub insert1 { my ( $ra, $elem, $index ) = @_; @$ra = @$ra[0 .. $index-1], $elem, @$ra[$index .. @$ra-1]; } # called as insert1( \@ary, 1, $_ ) for $START .. $END

If I swap $elem and $index (i.e. insert 1 at an index from $START to $END) I get:

qwurx [shmem] ~> perl 574821.pl 600 700 1000 Array size: 1000 Inserting: 600 .. 700 Rate radiant splicing radiant 30.5/s -- -98% splicing 1672/s 5377% --

The insert somewhere in the middle is more expensive, that's why $_/10 for @params here.

My perl:

$ perl -v This is perl, v5.8.8 built for i586-linux-thread-multi ...

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}