in reply to How to select the code on basis of memory usage and execution time.
print does IO by way of a system call, which means that you have at least one context switch into kernel mode (to perform the system call) and one context switch out of kernel mode (to return control to the process running perl), and it's likely a blocking system call, so the minor difference between pushing a couple of arguments onto the stack and making a sub call in Perl is mostly immaterial. Besides that, an important question is how often $flag is true, or how often FUNC() gets called, or if this is anywhere near a critical loop in your program (though I have confidence that it's not).
In other words, don't worry about this code. It's not likely to matter, even if you could measure it without taking into account the system call.
|
|---|