Yes, that's faster. But it doesn't work (consider not removing elements when $index=0). When I fixed youre code, it became slower -- though it may be possible to optimize it again:
# the fix: @items = grep { my $keep = !exists $del{$_}; $i++; $index -= ($i < $index) unless $keep; $keep } @items; # the results Benchmark: timing 100000 iterations of BrowserUk, dpuu... BrowserUk: 13 wallclock secs (13.72 usr + 0.00 sys = 13.72 CPU) @ 72 +88.63/s (n=100000) dpuu: 10 wallclock secs ( 9.88 usr + 0.00 sys = 9.88 CPU) @ 10 +117.36/s (n=100000) Rate BrowserUk dpuu dpuu 10117/s 39% -- BrowserUk 7289/s -- -28%
To provide fair comparison, here are the results I got running your original benchmark on my system (note the increased iteration count -- my system is 5X faster):
Benchmark: timing 100000 iterations of BrowserUk, dpuu... BrowserUk: 10 wallclock secs ( 9.26 usr + 0.00 sys = 9.26 CPU) @ 10 +795.64/s (n=100000) dpuu: 10 wallclock secs ( 9.87 usr + 0.01 sys = 9.88 CPU) @ 10 +118.39/s (n=100000) Rate dpuu BrowserUk dpuu 10118/s -- -6% BrowserUk 10796/s 7% --
in constrast to your +25/-20%. --Dave

Update: The required optimization is this twisted expression:

@items = grep { ++$i && !exists $del{$_} || ($index -= $i-1 <= $index) + && 0 } @items;

In reply to Re: Re: round-robin on varying sequence by dpuu
in thread round-robin on varying sequence by dpuu

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.