in reply to Sort this data
There was a huge error in this test (and I'm stupid for not using strict in it). I was testing @c where I should have been testing @a. I am now going to replace the bad results with the GOOD results.Here's a benchmark. Six methods were tested, and run for 5 seconds, three times; once on a set of 100 elements, once on 1000, and once on 10000.
use Benchmark; for $SIZE (100, 1000, 10000) { timethese(-5, { sp_fr_pu => sub { my @a = (1..$SIZE); my @b; while (my @c = splice(@a, 0, 4)) { push @b, { @c } } }, sp_bk_un => sub { my @a = (1..$SIZE); my @b; while (@a and my @c = splice(@a, -4)) { unshift @b, { @c } } }, sp_bk_in => sub { my @a = (1..$SIZE); my @b; $#b = int(@a / 4); my $i = $#b; while (@a and my @c = splice(@a, -4)) { $b[$i--] = { @c } } }, in_fr_pu => sub { my @a = (1..$SIZE); my @b; my $i = 0; while ($i < @a) { push @b, { @a[$i .. $i + 3] }; $i += 4; } }, sh_fr_pu => sub { my @a = (1..$SIZE); my @b; while (@a) { push @b, { map shift(@a), 1..4 } } }, sp_bk_rv => sub { my @a = (1..$SIZE); my @b; while (@a and my @c = splice(@a, -4)) { push @b, { @c } } @b = reverse @b; }, }); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Sort this data
by japhy (Canon) on Nov 19, 2000 at 23:59 UTC | |
|
HUGE ERROR in results (Re: Re: Sort this data)
by japhy (Canon) on Nov 20, 2000 at 01:35 UTC |