in reply to Re: Re: Re: Filling buckets
in thread Filling buckets

aha: I should've asked for this myself. A couple things wrong with it:

  1. the dws() routine shifts @array instead of @_, so all code that ran after it (everything but danger()) was passed an empty @array. This is the big source of differences.(dws() also needs fixing to return the actual buckets).
  2. the repson() routine does a my @array = shift when it should do a my @array = @_ (only affects its own standing).

below are corrected dws() and repson() routines, and I've taken this opportunity to include a fix for my silly holdover in my danger() routine:

sub dws { my $nbuckets = 3;#shift; # number of buckets to divide @array int +o my @bucket; # @{$bucket{0 .. $nbuckets - 1}} are the bucket +s foreach my $n( 0 .. $nbuckets - 1) { foreach my $size (1 .. int(0.9999 + @_ /($nbuckets - $n))){ push @{$bucket[$n]}, shift @_; } } return @bucket; } sub repson { my @array = @_; my $num = 3; # buckets my $cnt = @array; # total items my $base = int($cnt/$num); # } my $left = $cnt % $num; # } $cnt = ($base * $num) + $left my @buckets; for (1..$num) { push @buckets, [ splice(@array,0,$base + ($left-- > 0 && 1 +) ) ]; } @buckets; } sub danger_fixed { my $buckets = shift; my @list = @_; my $mod = @list % $buckets; my $inc = int(@list / $buckets); map{ [splice @list, 0, $inc + (--$mod >= 0)] } 0 .. $buckets - 1; } relative results: Rate dws tilly eg fast_sp2 tillyr danger repson fast_sp1 + danger1 fastolfe dws 1034/s -- -1% -18% -32% -34% -36% -36% -40% + -42% -52% tilly 1043/s 1% -- -17% -31% -33% -35% -35% -39% + -42% -52% eg 1263/s 22% 21% -- -17% -19% -21% -22% -27% + -30% -42% fast_sp2 1516/s 47% 45% 20% -- -3% -5% -6% -12% + -16% -30% tillyr 1564/s 51% 50% 24% 3% -- -3% -3% -9% + -13% -28% danger 1604/s 55% 54% 27% 6% 3% -- -1% -7% + -11% -26% repson 1613/s 56% 55% 28% 6% 3% 1% -- -6% + -10% -26% fast_sp1 1723/s 67% 65% 36% 14% 10% 7% 7% -- + -4% -21% danger1 1796/s 74% 72% 42% 18% 15% 12% 11% 4% + -- -17% fastolfe 2174/s 110% 108% 72% 43% 39% 36% 35% 26% + 21% --