缓慢的朱莉娅启动蒂姆

2024-04-25 12:29:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在探索使用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是去年茱莉亚一位作者的名言。这个策略有什么困难吗?在

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.


Tags: andthetoinhellosotimeis
2条回答

不幸的是,Julia现在需要很多时间来开始,所以几乎不可能在bash脚本中使用它来解决真正的小问题。你可能会得到一个更倾向于julia的结果,这个复杂的例子使用循环来做很多次事情,但是如果提前2-4秒,它需要一个很大的问题来有足够的时间来追赶。如果启动时间对你的科学计算来说是最重要的,朱莉娅还没有准备好。在

同样不公平的比较是用愚蠢的递归公式计算斐波纳契数。如果你超过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

正如您所要求的加速问题的方法,这里是:

^{pr2}$

我在评论中提到的branch现在已经被合并了,julia比以往任何时候都更适合创业(什么都不做)。在

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

real    0m0.622s
user    0m1.013s
sys     0m0.624s

它现在可以在夜间构建中使用,并将包含在下一个0.3版本中。在

相关问题 更多 >