为什么python math.factorial(x)非常快?

时间:2012-07-03 15:15:43

标签: python

我有一个问题,为什么python数值计算速度非常快? 例如,以下代码运行时间短于一秒

import  math
print math.factorial(10000)

为什么???

1 个答案:

答案 0 :(得分:20)

math module's functions在C:

中实现
  

它提供对C标准定义的数学函数的访问。

通过在C中使用高效算法,您可以获得快速结果。

如果您问为什么此特定操作速度如此之快,请参阅Why is math.factorial much slower in Python 2.x than 3.x?C code itself

相关问题