Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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

by aaron_baugher (Curate)
on Oct 05, 2012 at 12:07 UTC ( [id://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 (Canon) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://997459]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (12)
As of 2024-04-16 07:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found