我想precompile
一些函数而不运行它们。我尝试了一个简单的例子(见下文),但它似乎没有做任何事情。
我怎样才能让它发挥作用? Jupyter
笔记本中是否有额外的“陷阱”?
修改
是的,我坚持使用类型定义试图让precompile
做某事。
$ ./julia
_
_ _ _(_)_ | A fresh approach to technical computing
(_) | (_) (_) | Documentation: https://docs.julialang.org
_ _ _| |_ __ _ | Type "?help" for help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 0.6.2 (2017-12-13 18:08 UTC)
_/ |\__'_|_|_|\__'_| |
|__/ | x86_64-redhat-linux
julia> versioninfo()
Julia Version 0.6.2
Commit d386e40c17 (2017-12-13 18:08 UTC)
Platform Info:
OS: Linux (x86_64-redhat-linux)
CPU: Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
WORD_SIZE: 64
BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
LAPACK: libopenblas64_
LIBM: libopenlibm
LLVM: libLLVM-3.9.1 (ORCJIT, skylake)
julia> function myf(x::Vector{Int64})::Vector{Int64}
sort(x)
end
myf (generic function with 1 method)
julia> precompile(myf, (Vector{Int64},))
true
julia> @time myf([4,3,5,7,3,2,3,5,6,6,3,98]::Vector{Int64})
0.038889 seconds (1.42 k allocations: 80.390 KiB)
12-element Array{Int64,1}:
2
3
3
3
3
4
5
5
6
6
7
98
julia> @time myf([4,3,5,7,3,2,3,5,6,6,3,98]::Vector{Int64})
0.000012 seconds (7 allocations: 592 bytes)
12-element Array{Int64,1}:
2
3
3
3
3
4
5
5
6
6
7
98