1-Python - 如何提升Python代码的性能
before
Python的性能一直是人们诟病的地方,所以,我们在日常的搬砖中,要注意使用技巧提高搬砖效率,也能加深你对Python的理解。
使用 if is
In [3]: %timeit -n 1000 [i for i in range(100000) if i == True]
3.38 ms ± 41.4 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
In [4]: %timeit -n 1000 [i for i in range(100000) if i is True]
2.6 ms ± 47.7 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
that's all,see also: