"Stefan Behnel" <stefan...@behnel.de> wrote

On another note, getting rid of the list comprehension and using a
generator expression will be even faster, since you won't have to
build the list.

I gave this suggestion a try. It is true for me when run in CPython 3.2:

However, it is no longer true when I run the same thing in Cython:
...
Lesson learned:

Sometimes, it can be worth splitting a loop in two, one with a tight filter for the values, and another one to work on the remaining values.

And another good example of how hard it is to guess the optimal
solution in performance terms. It is one area where nothing beats
trial and test. And another reason why premature optimisation should
be resisted! :-)

Alan G.

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to