导入模块的多个 versions/branches 以在 Julia 中进行基准测试

Importing multiple versions/branches of a module to benchmark in Julia

如何在 Julia 的单个脚本中使用同一模块的多个不同版本或分支?

例如如果我想对每个标记的版本进行基准测试。

(最近有人问了类似的问题,我回答错了,不过这可能还是有用的。)

编辑:我自己回答了这个问题,但我相信他们可能是更好的方法!

您可以 git 签出模块的不同版本,然后使用 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 tag

的输出来循环执行许多版本
for i in readlines(`git tag`)
    version2checkout = chomp(i)
    # checkout version and benchmark
end

另请注意,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 进程。