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

Re^3: Efficiency of map vs. more verbose basic/fundamental code

by aaron_baugher (Deacon)
on Oct 05, 2012 at 12:07 UTC ( #997459=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Efficiency of map vs. more verbose basic/fundamental code
in thread Efficiency of map vs. more verbose basic/fundamental code

Two important things in running a benchmark are:

1) Make sure your subroutines are doing the same thing with the same data. I made the mistake once of setting up the data outside the subroutine and then editing it in place, so that the second routine to run was working with different data than the first. Make sure each one starts with the same thing and has the same result.

2) Avoid anything that adds overhead which could overshadow the time used by the function that you're actually trying to benchmark. If you're comparing for and map, just include them and as little else as possible. Especially avoid any system calls, IO like printing, etc. Print the results once to make sure your outputs match, but then remove those statements. A difference of nanoseconds won't show through the random noise if you're calling functions that take milliseconds.

Aaron B.
Available for small or large Perl jobs; see my home node.


Comment on Re^3: Efficiency of map vs. more verbose basic/fundamental code
Select or Download Code
Re^4: Efficiency of map vs. more verbose basic/fundamental code
by Marshall (Prior) on Oct 10, 2012 at 04:33 UTC
    I like this answer.
    In recent Perl, a "for" and a "map" statement will be almost identical in performance.

    Disk I/O statements especially can confuse benchmarks. That is because the Disk/File System has caching algorithms. I have one program that takes 7 seconds for the first search. The subsequent searches take like <1 second.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (10)
As of 2014-10-20 21:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (92 votes), past polls