gpt4 book ai didi

python - 缓慢的 Julia 启动时间

转载 作者:太空狗 更新时间:2023-10-29 18:02:25 26 4
gpt4 key购买 nike

我正在探索使用 Julia 作为通用科学计算语言(而不是 python),但它的启动时间非常缓慢。

有什么办法可以加快速度吗?

$ time python -c 'print "Hello"'
Hello

real 0m0.030s
user 0m0.018s
sys 0m0.010s

$ time julia -e 'println("Hello")'
Hello

real 0m4.614s
user 0m4.644s
sys 0m0.116s

附录:Here是去年一位 Julia 作者的话。这个策略有什么困难吗?

Most of Julia is written in itself, then parsed, type-inferred and jitted, so bootstrapping the entire system from scratch takes some 15-20 seconds. To make it faster, we have a staged system where we parse, type-infer, and then cache a serialized version of the type-inferred AST in the file sys.ji. This file is then loaded and used to run the system when you run julia. No LLVM code or machine code is cached in sys.ji, however, so all the LLVM jitting still needs to be done every time julia starts up, which therefore takes about 2 seconds.

This 2-second startup delay is quite annoying and we have a plan for fixing it. The basic plan is to be able to compile whole Julia programs to binaries: either executables that can be run or .so/.dylib shared libraries that can be called from other programs as though they were simply shared C libraries. The startup time for a binary will be like any other C program, so the 2-second startup delay will vanish.

最佳答案

不幸的是,Julia 目前使用大量时间来启动,因此几乎不可能在 bash 脚本中使用它来解决非常小的问题。通过一个使用循环多次执行操作的复杂示例,您可能会得到一个对 julia 更有利的结果,但是在 2-4 秒的领先优势下,它需要一个大问题才能有足够的时间 catch 。如果启动时间对您的科学计算最重要,那么 Julia 还没有准备好。

一个同样不公平的比较是使用愚蠢的递归公式来计算斐波那契数。如果超过 26,情况会变得更糟。还要注意代码的 Julia 版本是多么紧凑。

>>> ivarne~/dev/julia$ time julia -e 'fib(x) = x<2?1:fib(x-1)+fib(x-2);println(fib(36))'
24157817

real 0m2.763s
user 0m2.776s
sys 0m0.093s
>>> time python -c $'def fib(x):\n if x<2: return 1\n else: return fib(x-1)+ fib(x-2);\nprint fib(36)'
24157817

real 0m8.371s
user 0m8.336s
sys 0m0.025s

当你要求一种加速问题的方法时;这是:

>>> time echo "Hello"
Hello

real 0m0.000s
user 0m0.000s
sys 0m0.000s

关于python - 缓慢的 Julia 启动时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19009824/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com