[issue32180] bool() vs len() > 0 on lists

2017-12-01 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I'm sure adding list.__bool__() will not affect the performance. The real source of the difference is explained on the StackOverflow link. PEP 8 contains a rule for testing the emptiness of a container. -- resolution: -> not a bug stage: -> resolv

[issue32180] bool() vs len() > 0 on lists

2017-12-01 Thread Raymond Hettinger
Raymond Hettinger added the comment: ISTM that there isn't a real issue here and the discussions of proper timing technique and micro-optimizations are more suitable for StackOverflow. -- nosy: +rhettinger ___ Python tracker

[issue32180] bool() vs len() > 0 on lists

2017-11-30 Thread Дилян Палаузов
Дилян Палаузов added the comment: Is the speedup a matter of adding "__bool__" to list_methods in object/listobject.c? In any case, I am not in the internals of cpython, so that I am not going to provide a patch. With PyObject_Bool I meant PyObject_IsTrue. -- __

[issue32180] bool() vs len() > 0 on lists

2017-11-30 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I don't know what should mean PyObject_Bool(), but in C code you should use PyObject_IsTrue() for getting the boolean value of the object. -- ___ Python tracker __

[issue32180] bool() vs len() > 0 on lists

2017-11-30 Thread Дилян Палаузов
Дилян Палаузов added the comment: Under these circumstances https://wiki.python.org/moin/PythonSpeed/PerformanceTips shall be updated to state that "len('a list') > 0" is slower than "True if 'a list' else False" -- ___ Python tracker

[issue32180] bool() vs len() > 0 on lists

2017-11-30 Thread Дилян Палаузов
Дилян Палаузов added the comment: To my understanding this optimization (bool([]) faster than len([])) cannot be made until PyObject_Bool is introduced, similar to PyObject_Repr and PyObject_Length. Am I not going to provide a patch. -- status: pending -> open __

[issue32180] bool() vs len() > 0 on lists

2017-11-30 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: The cause of len() been faster than bool() is the same as why repr() is faster than str(). [1] len() and repr() are functions that just call corresponding slots, while bool() and str() are constructors. In most cases you shouldn't use `bool(obj)` or `len(ob

[issue32180] bool() vs len() > 0 on lists

2017-11-30 Thread Дилян Палаузов
New submission from Дилян Палаузов : Please make bool() on lists at least as fast as len() > 0 on lists is. The trivial approach would be to define __bool__ on lists, that do something like "True if self else False". python3 Python 3.6.3+ (heads/3.6-dirty:2b5cbbb13c, Nov 1 2017, 19:03:09)