写一个脚本,因为涉及到很多行的文本,所以要跑几十分钟。
这个时候看到那个 == 就在想,Python的文本比较是怎么实现的?如果我手动len()先比一下会不会快一点?求老司机带路
这个时候看到那个 == 就在想,Python的文本比较是怎么实现的?如果我手动len()先比一下会不会快一点?求老司机带路
1
oott123 Apr 20, 2015 我认为这种自作聪明的“优化”只会更慢……
毕竟写 Python 的那群人想的不比你少 :) |
2
lichun Apr 20, 2015 lichun@ubuntu:~$ python -m profile str_equal_test.py
3 function calls in 0.033 seconds lichun@ubuntu:~$ python -m profile str_len_equal_test.py 200003 function calls in 1.206 seconds |
4
laike9m Apr 20, 2015
字符串比较难道不是从头开始一个一个字符比么,至少是类似的吧
|
5
lerry Apr 20, 2015
pypy 会不会快一点?纯猜测
|