in reply to Re: Sorting based on filesize.
in thread Sorting based on filesize.
You need the Schwartzian Transform
I'd say it's doubtful. Clearly, stat is slow, but it's not a slouch, and the Schwartz Transform adds its own overhead. I suspect the sweet spot where the ST pulls ahead is higher than you think.
If we want to pursue this approach, an improvement will be to employ a Guttman-Rosler Transform:
my @sorted = map substr($_, 4) => sort map pack(`L',$_) . $_ => @files; # but see eyepopslikeamosquito's comment below
By being able to dip down and call the sort function without a code block will show greater benefits. With the proviso that one might have to pack with 8 byte 'Q' quads, for systems with filesizes larger than 2Gb.
With that in mind, it's probably all premature optimisation. I would wait until the snippet showed itself as being a performance pig before going to all this bother:
sort { -s $a <=> -s $b } @files
... does have the distinct advantage of being eminently readable.
- another intruder with the mooring of the heat of the Perl
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Sorting based on filesize.
by eyepopslikeamosquito (Archbishop) on Jul 20, 2004 at 08:41 UTC | |
|
•Re^3: Sorting based on filesize.
by merlyn (Sage) on Jul 20, 2004 at 13:20 UTC | |
by pbeckingham (Parson) on Jul 21, 2004 at 00:46 UTC |