in reply to Re^2: Sort the file names a list
in thread Sort the file names a list

ikegami++! I'd seen the GRT discussed, but never tried it myself. I guess I never thought enough about it, and my first-glance assessment was that memoization was faster. That'll teach me to make assumptions without testing!

Oh, and I saw the memoization technique called the "Orcish (or-cache) maneuver" in Perl Underground 2 (credit japhy).

$,=' ';$\=',';$_=[qw,Just another Perl hacker,];print@$_;

Replies are listed 'Best First'.
Re^4: Sort the file names a list
by ikegami (Patriarch) on Aug 31, 2009 at 16:50 UTC
    I had a bug. Fixing it affected the times. You'll note that your solution actually slows down the sorting.

      I thought that it might, for a small set of inputs. The overhead of creating and populating the hash, as well as assignments to two new lexicals would only be overcome with a significantly larger data set.

      I wonder, though. Yep. Changing it to this:

      { my %cache; sub memoized { ( $cache{$a} ||= substr($a, -(19+20), 19) ) cmp ( $cache{$b} ||= substr($b, -(19+20), 19) ); } }

      gives a slight increase in speed (but my benchmarks are varying wildly right now. Maintaining ranking, but % differences are all over the board.)

      Rate st memoized naive grt st 10281/s -- -6% -51% -54% memoized 10930/s 6% -- -48% -51% naive 20942/s 104% 92% -- -5% grt 22143/s 115% 103% 6% --
      $,=' ';$\=',';$_=[qw,Just another Perl hacker,];print@$_;