Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: Benchmark Schwartzian Transform

by thunders (Priest)
on Mar 16, 2015 at 22:23 UTC ( #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?

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2021-09-23 00:06 GMT
Find Nodes?
    Voting Booth?

    No recent polls found