如何在Julia中的单个脚本中使用同一模块的多个不同版本或分支?
如果我想对每个标记的版本进行基准测试的话。
(最近有人问了一个类似的问题,我回答错了,但无论如何这可能是有用的。)
编辑:我自己也回答过这个问题,但我相信他们会是一个更好的方法!
发布于 2016-08-30 10:30:17
您只需签出模块的不同版本,然后使用benchmarkTools.jl进行基准测试。但是,最好使用多个脚本(或者至少忽略第一个试用版)(更多信息请参见这个注释Importing multiple versions of the same Module/Package for Benchmarking )。
例如:
packagedir = Pkg.dir("DSP")
version2checkout = "v0.0.7"
run(`cd $packagedir`); run(`git checkout tags/$version2checkout`)
import DSP
# do all your benmarking stuff
# start again防止您不得不复制模块,但仍然有点笨重,我想。您甚至可以通过捕获git标记的输出,在循环中对许多版本执行此操作。
for i in readlines(`git tag`)
version2checkout = chomp(i)
# checkout version and benchmark
end发布于 2016-08-30 22:16:38
还请注意,Pkg.checkout采用一个可选的branch参数:
help?> Pkg.checkout
checkout(pkg, [branch="master"]; merge=true, pull=true)
Checkout the Pkg.dir(pkg) repo to the branch branch. Defaults to checking
out the "master" branch. To go back to using the newest compatible released
version, use Pkg.free(pkg). Changes are merged (fast-forward only) if the
keyword argument merge == true, and the latest version is pulled from the
upstream repo if pull == true.所以你可以做Pkg.checkout("MyPackage", "v0.6.0")。为了确保重新加载模块,workspace()函数可能会派上用场;或者可以为每个包版本执行一个新的Julia进程。
https://stackoverflow.com/questions/39225066
复制相似问题