Julia语言每次编译脚本,我们不能用julia编译二进制文件吗?我尝试了一个带有println函数的小helloworld脚本,julia花了2,3秒来显示输出!如果我们可以制作二进制文件而不是每次编译都会更好
更新:朱莉娅有一些变化,因为我问过这个问题.虽然我不再关注julia的更新,因为我已经问过这个问题,如果你正在寻找类似的东西,请查看以下答案和关注julia的人的评论.
此外,很高兴知道现在加载脚本大约需要150毫秒.
基本上我的情况就是这个.我有一个模块(也导入了许多其他模块).
我有一个脚本,如:
import MyModule
tic()
MyModule.main()
tic()
MyModule.main()
Run Code Online (Sandbox Code Playgroud)
在MyModule中:
__precompile__()
module MyModule
export main
function main()
toc()
...
end
end
Run Code Online (Sandbox Code Playgroud)
第一个toc()呼叫输出大约20秒.第二个输出2.3e-5.任何人都可以猜测时间的去向吗?Julia是否在第一次调用模块时进行某种初始化,我怎么能弄清楚它是什么?
我想知道如何用Julia语言确定a file.jl是否作为脚本运行,例如在调用中:
bash$ julia file.jl
Run Code Online (Sandbox Code Playgroud)
例如,它仅在这种情况下必须启动一个函数main。因此,我可以使用include('file.jl'),而无需实际执行功能。
具体来说,我正在寻找一个已经在python问题中回答的类似问题:
def main():
# does something
if __name__ == '__main__':
main()
Run Code Online (Sandbox Code Playgroud)
编辑:更具体地说,当在非交互式(例如脚本)环境中使用时,该方法Base.isinteractive(请参见此处)不能解决问题include('file.jl')。
function somefun()
x::Int = 1
x = 0.5
end
Run Code Online (Sandbox Code Playgroud)
编译时没有任何警告。当然,调用它会产生 InexactError:Int64(0.5)。问题:你能强制执行编译时检查吗?
我正在运行此问题中显示的代码。我希望它第二次和第三次运行得更快(第一次运行需要时间来编译代码)。然而,它似乎花费了与第一次相同的时间。我怎样才能让这段代码运行得更快?
\n编辑:我通过在 Linux 终端上发出命令来运行代码:julia mycode.jl
我尝试按照 @Przemyslaw Szufel 的答案中的说明进行操作,但出现以下错误:
\njulia> create_sysimage(["Plots"], sysimage_path="sys_plots.so", precompile_execution_file="precompile_plots.jl")\n\nERROR: MethodError: no method matching create_sysimage(::Array{String,1}; sysimage_path="sys_plots.so", precompile_execution_file="precompile_plots.jl")\nClosest candidates are:\n create_sysimage() at /home/cardio/.julia/packages/PackageCompiler/2yhCw/src/PackageCompiler.jl:462 got unsupported keyword arguments "sysimage_path", "precompile_execution_file"\n create_sysimage(::Union{Array{Symbol,1}, Symbol}; sysimage_path, project, precompile_execution_file, precompile_statements_file, incremental, filter_stdlibs, replace_default, base_sysimage, isapp, julia_init_c_file, version, compat_level, soname, cpu_target, script) at /home/cardio/.julia/packages/PackageCompiler/2yhCw/src/PackageCompiler.jl:462\nStacktrace:\n [1] top-level scope at REPL[25]:1\nRun Code Online (Sandbox Code Playgroud)\n我在 Debian Stable Linux 上使用 Julia:Debian \xe2\x9b\xac julia/1.5.3+dfsg-3
\n我最近在Julia转移了我的代码.我想知道如何在命令行中执行Julia代码?
我知道Julia代码可以通过运行一次来编译.
但问题是我需要为集群上的模拟模型进行参数扫描,在那里我只能使用命令行 - 而不是REPL.
在群集上运行模拟复制的最佳实践是什么?