def main():
for i in xrange(10**8):
pass
main()
This piece of code in Python runs in (Note: The timing is done with the time function in BASH in Linux.)
(Python中的这段代码在其中运行(注意:计时是通过Linux中的BASH中的time函数完成的。))
real 0m1.841s
user 0m1.828s
sys 0m0.012s
However, if the for loop isn't placed within a function,
(但是,如果for循环未放在函数内,)
for i in xrange(10**8):
pass
then it runs for a much longer time:
(那么它会运行更长的时间:)
real 0m4.543s
user 0m4.524s
sys 0m0.012s
Why is this?
(为什么是这样?)
ask by thedoctar translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…