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% --

In reply to Re: Re: Re: Re: Filling buckets by danger
in thread Filling buckets by meonkeys

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.