Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2019-04-26 07:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I am most likely to install a new module from CPAN if:
















    Results (128 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!