On Wed, Dec 28, 2011 at 06:39, Jaidev Deshpande <deshpande.jai...@gmail.com> wrote: > Hi > > It is said that function calls are expensive. Does that mean one must > use available methods instead?
For the most part, it usually doesn't matter enough to care about. Whether you use the methods or the functions should be dominated by other concerns like readability and genericity. Typically, this means that you do want the methods, but not for performance reasons. Note that when we say "function calls are expensive", we mean that the call overhead for functions and methods implemented in pure Python is expensive relative to functions and methods implemented via C. By "overhead", we mean the extra time that isn't related to the actual computation itself, like setting up the stack frame, packing and unpacking the arguments, etc. Extension functions/methods don't need to do as much of this. Really, the performance difference only matters when you have thousands of calls in a tight loop, at which point you should be thinking about reorganizing your algorithm anyways. This is a micro-optimization. Micro-optimizations have their place: namely, after you have done all of the macro-optimizations that you can. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion