所以,今天我决定尝试朱莉娅而且我遇到了一些奇怪的事情,我无法理解其原因,也没有找到适合我的搜索查询的答案所以我在这里......
首先,我想要对Python进行基准测试,我决定使用这个非常简单的代码.
def test():
start = time()
a = 1
while a < 10000000:
a+=1
print(time() - start)
Run Code Online (Sandbox Code Playgroud)
在我的机器上用Python 3.3执行大约需要0.9秒.然后我在朱莉娅跑了以下.
start = time()
a = 1
while a < 10000000
a+=1
end
print(time() - start)
Run Code Online (Sandbox Code Playgroud)
执行需要约0.7秒.所以我得出结论,Julia中的简单算术性能是〜= Python.
然而,当我把它变成一个函数时,我偶然发现了一个我没想到的奇怪的东西,这让我的结果变得不可思议.
function test_arithmetic()
start = time()
a = 1
while a < 10000000
a+=1
end
print(time() - start)
end
test_arithmetic()
Run Code Online (Sandbox Code Playgroud)
这个codenippet只需要0.1秒执行,为什么会这样?