Message307294
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)
[GCC 6.4.1 20171025] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import timeit
>>> timeit.timeit('len([]) > 0')
0.0983404889702797
>>> timeit.timeit('bool([])')
0.15502946823835373
>>> timeit.timeit('True if [] else False')
0.03108721226453781
>>> timeit.timeit('len([1]) > 0')
0.11656427383422852
>>> timeit.timeit('bool([1])')
0.19317257404327393
>>> timeit.timeit('True if [1] else False')
0.057590410113334656 |
|
Date |
User |
Action |
Args |
2017-11-30 11:31:47 | dilyan.palauzov | set | recipients:
+ dilyan.palauzov |
2017-11-30 11:31:47 | dilyan.palauzov | set | messageid: <1512041507.48.0.213398074469.issue32180@psf.upfronthosting.co.za> |
2017-11-30 11:31:47 | dilyan.palauzov | link | issue32180 messages |
2017-11-30 11:31:47 | dilyan.palauzov | create | |
|