SQL is going to perform sorting logic faster than pretty much anything else, provided your query isn't doing anything silly and the tables involved are properly keyed and indexed.
If you're really worried about overhead, you might consider making a c++ function with a perl wrapper. The perl interface is great, but if you need to do any heavy lifting, it should probably be done elsewhere.
|