Which is faster?

Fredrik Lundh fredrik at pythonware.com
Sat Aug 30 01:57:07 EDT 2008


cnb wrote:

> For a big nbr of it might matter?
> Is av_grade O(n*2) and the first O(n)  when it comes to adding or is
> "sum x for x in y" just traversing the list ones, accumulating the
> values, it doesnt first build the list and then travese it for sum?

sum() doesn't build a list, but even if it would do that, it'd still be 
O(n) -- looping over an array twice doesn't change the time complexity.

to find out which one's actually faster, benchmark them.

</F>




More information about the Python-list mailing list