Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • 2
    You are comparing apples and pears here. You are comparing assignment to a local variable to invoking a function, two very different things. Commented Feb 1, 2013 at 14:29
  • 1
    And how did you call timeit to get negative numbers? Commented Feb 1, 2013 at 14:30
  • 1
    I'd say 5x slower is actually fast. I mean, calling a function is much more work then a simple assignment. You have to 1) look if the function exist(that's a global lookup which is slow) 2) Pack the arguments, 3) Call the function which itself has to unpack the arguments 4) execute the code 5) Return the object. (The fact that I used 5 steps is just a chance. I don't think it has anything to do with the code being 5 times slower) Commented Feb 1, 2013 at 14:32
  • Calling timeit.timeit() is measuring the time it takes to execute nothing a million times. Subtracting timeit.timeit() from timeit.timeit() may be negative. Commented Feb 1, 2013 at 14:34
  • Martijn: That was the point (unless I did it wrong) to compare doing something in a function vs doing it outside a function. I essentially want to know what the added overhead of the function call itself is. and I commented out my timeit method to show what I was doing. Commented Feb 1, 2013 at 14:34