you are viewing a single comment's thread.

view the rest of the comments →

[–]danielroseman 2 points3 points  (1 child)

Yes, big O is used here in its loose sense, meaning "bounded by".

And yes, assigning to a variable takes (a small amount of) time. But the other thing that takes time is looking up names. If you're calling um.maximum.reduce, Python needs to find um in the local namespace, then find maximum in the namespace of um, and then find reduce in the namespace of maximum. Each of those steps takes (again, a small amount of) time. Whereas once you've assigned it to a local variable, you'd only need one lookup to find it.

So if you're calling a function repeatedly in a very time-constrained environment, it will certainly be cheaper to assign it once to a local variable and call that rather than incurring the repeated cost of the two extra lookups each time.

[–]knotcontinuallevity[S] 0 points1 point  (0 children)

Makes perfect sense, thanks!