Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

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

by aaron_baugher (Curate)
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.

Replies are listed 'Best First'.
Re^4: Efficiency of map vs. more verbose basic/fundamental code
by Marshall (Abbot) 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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://997459]
[Happy-the-monk]: Goody-goody!
[Discipulus]: still happy Happy-the-monk? even in 2018? good for you.. ;=)
[choroba]: Good morning!

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2018-01-23 08:44 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (242 votes). Check out past polls.