Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re^3: Linked lists as arrays: inserting values

by ikegami (Pope)
on Sep 25, 2006 at 23:37 UTC ( #574845=note: print w/replies, xml ) Need Help??

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];
(@$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 500 600 1000 Array size: 1000 Inserting: 500 .. 600 Rate radiant splicing radiant 17.3/s -- -99% splicing 1470/s 8392% --

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://574845]
and !@monks...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2017-06-27 09:57 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (601 votes). Check out past polls.