Python战俘更快的求幂
示例
从命令行使用timeit模块:
> python -m timeit 'for x in xrange(50000): b = x**3' 10 loops, best of 3: 51.2 msec per loop > python -m timeit 'from math import pow' 'for x in xrange(50000): b = pow(x,3)' 100 loops, best of 3: 9.15 msec per loop
内置**运算符通常派上用场,但是如果性能至关重要,请使用math.pow。但是请务必注意,即使参数为整数,pow也会返回浮点数:
> from math import pow > pow(5,5) 3125.0
热门推荐
10 感谢韩语老师祝福语简短
11 升职文案高级祝福语简短
12 花童结婚祝福语大全简短
13 向国庆送祝福语简短
14 什么寄语简短祝福语女生
15 客户回礼祝福语大全简短
16 女孩生日祝福语简短创意
17 家长回复节日祝福语简短
18 给外婆敬酒祝福语简短