简体   繁体   English

为什么在python中print(456 ** 5582)这么快?

[英]Why is print(456 ** 5582) so fast in python?

I've tried many numbers but it runs in like O(1) time. 我尝试了很多数字,但是它的运行时间像O(1)一样。 Why is this so fast? 为什么这么快? Can someone please explain how ** operator actually works. 有人可以解释一下**运算符的实际工作原理。

The claim that this is O(1) is incorrect. 关于这是O(1)的说法是不正确的。

>>> %timeit 456**558 
6.22 µs ± 9.22 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
>>> %timeit 456**5582  
237 µs ± 226 ns per loop (mean ± std. dev. of 7 runs, 1000 loops each)
>>> %timeit 456**55822
9.54 ms ± 13.2 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

See here for the CPython implementation. 有关CPython实现的信息,请参见here

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM