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


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

Here's my benchmarking code, demolish it at will:

First rule of Benchmarking, make sure the code you are benchmarking actually works!

@$ra = @$ra[0 ..$ index-1], $elem, @$ra[$index .. @$ra-1];
means
(@$ra = @$ra[0 ..$ index-1]), $elem, @$ra[$index .. @$ra-1];
You want
@$ra = ( @$ra[0 ..$ index-1], $elem, @$ra[$index .. @$ra-1] );

Also, your arguments are backwards:
insert1( \@ary, 1, $_ ) for $START .. $END
insert2( \@ary, 1 ,$_ ) for $START .. $END
should be
insert1( \@ary, $_, 1 ) for $START .. $END
insert2( \@ary ,$_, 1 ) for $START .. $END

Once fixed (and setting the loop count to -3 cause it was taking forever):

>perl 574845.pl 500 600 1000 Array size: 1000 Inserting: 500 .. 600 Rate radiant splicing radiant 17.3/s -- -99% splicing 1470/s 8392% --