Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Benchmark Schwartzian Transform

by thunders (Priest)
on Mar 16, 2015 at 22:23 UTC ( [id://1120227]=note: print w/replies, xml ) Need Help??


in reply to Benchmark Schwartzian Transform

The Benchmark module is a big help with this sort of thing.

What the Schwartzian Transform does is reduce the overall number of calls to the function that computes the value of your item. Your sort is going to do roughly (n * log n) comparisons where n is the number of items in your list. If the function that computes the value of the list item is significantly more expensive than a simple comparison you want to reduce the number of calls to that more expensive function.

The map at the end of the Schwartzian transform only runs the function once for each element of the list. Of course you incur some overhead in building an arrayref, and looping again at the end, but for lists with many items reducing the number of computations can save a lot of cycles. You'll see very different results based on how expensive it is to compute the sort value.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1120227]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-03-29 15:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found