in reply to Re: Removing certain elements from an array
in thread Removing certain elements from an array
My opinion of Benchmark is very low - the results I generated seems to support this vauge memory of mine.
#!/os/dist/bin/perl -w use Benchmark; my @array = 0..10000; my @idxsToRemove = (); push @idxsToRemove, int( rand( 10000 ) ) for ( 0 .. 100 ); my %toRemoveIdx; @toRemoveIdx{@idxsToRemove} = (1)x@idxsToRemove; sub Tye { my @subarray = @array; @subarray = map { $toRemoveIdx{$_} ? () : $subarray[$_] } 0..$#sub +array; } sub btrott { my @subarray = @array; splice @subarray, $_, 1 for sort { $b <=> $a } @idxsToRemove; } imethese( shift @ARGV || -5, { 'Tye' => \&Tye, 'btrott' => \&btrott, } );
Generated these results:
Benchmark: running Tye, btrott, mikfire, each for at least 5 CPU seco +nds... Tye: 7 wallclock secs ( 5.98 usr + 0.00 sys = 5.98 CPU) @ 7 +.19/s (n=43) btrott: 6 wallclock secs ( 5.38 usr + 0.00 sys = 5.38 CPU) @ 63 +.01/s (n=339)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: RE: Re: Removing certain elements from an array
by tye (Sage) on Aug 24, 2000 at 22:16 UTC | |
|
RE: RE: Re: Removing certain elements from an array
by lhoward (Vicar) on Aug 24, 2000 at 22:18 UTC | |
|
RE: RE: Re: Removing certain elements from an array
by merlyn (Sage) on Aug 24, 2000 at 22:15 UTC | |
by mikfire (Deacon) on Aug 24, 2000 at 22:30 UTC | |
|
RE (tilly) 3: Removing certain elements from an array
by tilly (Archbishop) on Aug 25, 2000 at 00:17 UTC |