in reply to Linked lists as arrays: inserting values
@$ra = @$ra[0..$index-1], $elem, @$ra[$index..@$ra-1];
with
splice(@$ra,$index,0,$elem);
and using
cmpthese (5000, { radiantmatrix => sub { my $array = [1..1000]; insert_array_elem1($ +array,1,$_) for 50..100 }, use_splice => sub { my $array = [1..1000]; insert_array_elem2($arr +ay,1,$_) for 50..100 }, });
results in
Rate radiantmatrix use_splice radiantmatrix 467/s -- -83% use_splice 2762/s 492% --
radiantmatrix - use_splice :-)
--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}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Linked lists as arrays: inserting values
by Not_a_Number (Prior) on Sep 25, 2006 at 20:25 UTC | |
by shmem (Chancellor) on Sep 25, 2006 at 23:01 UTC | |
by ikegami (Patriarch) on Sep 25, 2006 at 23:37 UTC |