Next | Making Programs Faster | 5 |
Sort list of items by some non-apparent feature
Example: Sort filenames by last-modified date
The obvious method:
sort { -M $b <=> -M $a } (readdir D);
It calls -M over and over on the same files
Idea: Maybe we can speed this up as follows:
Construct data structure with both names and dates
Sort by date
Throw away dates
Next | Copyright © 2003 M. J. Dominus |