Julia 基准工具&x27;迟来的不在符号上工作 介绍

Julia 基准工具&x27;迟来的不在符号上工作 介绍,julia,benchmarking,Julia,Benchmarking,我有一个具有以下结构的目录 --> Report --> Problems --> PE_001 --> Julia PE_001.naive.jl PE_001.jl --> Benchmarks test_001.txt test_002.txt --> Results --> PE_002

我有一个具有以下结构的目录

--> Report
--> Problems
    --> PE_001
        --> Julia
            PE_001.naive.jl
            PE_001.jl
        --> Benchmarks
            test_001.txt
            test_002.txt
        --> Results
    --> PE_002
     .
     .
     .
    --> PE_XXX
--> Benchmark
我试图迭代所有Julia文件,并根据位于顶部目录
benchmark
下的基准数据对它们进行基准测试。我不想将
cd
放入每个目录,然后从julia命令行运行
@belapsed
,对每个函数分别计时

为了解决这个问题,我编写了下面的代码,应该位于上面层次结构中的
benchmarks
下。不过,为了便于说明,我将其稍微简化了一点

试图解决
编辑:下面的代码不遵循上面概述的层次结构。为了快速重现错误,以下代码的编写方式使所有文件都可以放在同一目录中

benchmark.jl

function PE_002(limit = 4*10^6)
    a, b = 0, 2
    while b < limit
        a, b = b, 4 * b + a
    end
    div(a + b - 2, 4)
end
PE_002.jl

function PE_002(limit = 4*10^6)
    a, b = 0, 2
    while b < limit
        a, b = b, 4 * b + a
    end
    div(a + b - 2, 4)
end

问题: 有趣的是,包含文件
PE_002
然后运行
@belapsed
可以工作,但是从目录中获取文件名,将其转换为符号,然后尝试使用
@belapsed
计时失败

我知道
@appead works
,但是,由于垃圾收集,它几乎不能满足我的需要

是否有一种简单的方法可以使用BenchmarkTools或类似的工具精确地对远程目录中的所有文件进行基准测试?

我只需要一个数字,表示每个文件的平均运行时间

编辑2:根据请求,我已在下面包含完整的错误消息

~/P/M/Julia-belaps ❯❯❯ julia benchmark.jl

9.495495495495496e-9
ERROR: LoadError: UndefVarError: f not defined
Stacktrace:
 [1] ##core#665() at /home/oisov/.julia/v0.6/BenchmarkTools/src/execution.jl:290
 [2] ##sample#666(::BenchmarkTools.Parameters) at /home/oisov/.julia/v0.6/BenchmarkTools/src/execution.jl:296
 [3] #_run#6(::Bool, ::String, ::Array{Any,1}, ::Function, ::BenchmarkTools.Benchmark{Symbol("##benchmark#664")}, ::BenchmarkTools.Parameters) at /home/oisov/.julia/v0.6/BenchmarkTools/src/execution.jl:324
 [4] (::BenchmarkTools.#kw##_run)(::Array{Any,1}, ::BenchmarkTools.#_run, ::BenchmarkTools.Benchmark{Symbol("##benchmark#664")}, ::BenchmarkTools.Parameters) at ./<missing>:0
 [5] anonymous at ./<missing>:?
 [6] #run_result#16(::Array{Any,1}, ::Function, ::BenchmarkTools.Benchmark{Symbol("##benchmark#664")}, ::BenchmarkTools.Parameters) at /home/oisov/.julia/v0.6/BenchmarkTools/src/execution.jl:40
 [7] (::BenchmarkTools.#kw##run_result)(::Array{Any,1}, ::BenchmarkTools.#run_result, ::BenchmarkTools.Benchmark{Symbol("##benchmark#664")}, ::BenchmarkTools.Parameters) at ./<missing>:0
 [8] #run#17(::Array{Any,1}, ::Function, ::BenchmarkTools.Benchmark{Symbol("##benchmark#664")}, ::BenchmarkTools.Parameters) at /home/oisov/.julia/v0.6/BenchmarkTools/src/execution.jl:43
 [9] (::Base.#kw##run)(::Array{Any,1}, ::Base.#run, ::BenchmarkTools.Benchmark{Symbol("##benchmark#664")}, ::BenchmarkTools.Parameters) at ./<missing>:0 (repeats 2 times)
 [10] macro expansion at /home/oisov/.julia/v0.6/BenchmarkTools/src/execution.jl:208 [inlined]
 [11] benchmark_files(::String) at /home/oisov/Programming/Misc/Julia-belaps/benchmark.jl:26
 [12] include_from_node1(::String) at ./loading.jl:569
 [13] include(::String) at ./sysimg.jl:14
 [14] process_options(::Base.JLOptions) at ./client.jl:305
 [15] _start() at ./client.jl:371
while loading /home/oisov/Programming/Misc/Julia-belaps/benchmark.jl, in expression starting on line 36
~/P/M/Julia belaps❯❯❯ julia benchmark.jl
9.495495495495496e-9
错误:LoadError:UndevarError:f未定义
堆栈跟踪:
[1] ##core#665()位于/home/oisov/.julia/v0.6/BenchmarkTools/src/execution.jl:290
[2] 样本666(::BenchmarkTools.Parameters)位于/home/oisov/.julia/v0.6/BenchmarkTools/src/execution.jl:296
[3] 在/home/oisov/.julia/v0.6/BenchmarkTools/src/execution.jl:324运行6(::Bool,::String,::数组{Any,1},::函数,::BenchmarkTools.Benchmark{Symbol(“#Benchmark#664”),::BenchmarkTools.Parameters)
[4] (::BenchmarkTools.#kw####u run)(::数组{Any,1},::BenchmarkTools.#u run,::BenchmarkTools.Benchmark{Symbol(“##Benchmark#664”),::BenchmarkTools.Parameters)at./:0
[5] 匿名地址:/?
[6] 在/home/oisov/.julia/v0.6/BenchmarkTools/src/execution.jl:40中运行结果16(::数组{Any,1},::函数,::BenchmarkTools.Benchmark{Symbol(“##Benchmark#664”),::BenchmarkTools.Parameters)
[7] (::BenchmarkTools.#kw##run#result)(::数组{Any,1},::BenchmarkTools.#run#result,::BenchmarkTools.Benchmark{Symbol(“#Benchmark#664”),::BenchmarkTools.Parameters)at./:0
[8] #在/home/oisov/.julia/v0.6/BenchmarkTools/src/execution.jl:43运行#17(::数组{Any,1},::函数,::BenchmarkTools.Benchmark{Symbol(“##Benchmark#664”),::BenchmarkTools.Parameters)
[9] (::Base.#kw#run)(::Array{Any,1},::Base.#run,::BenchmarkTools.Benchmark{Symbol(“#Benchmark#Benchmark#664”),::BenchmarkTools.Parameters)at./:0(重复2次)
[10] 宏扩展位于/home/oisov/.julia/v0.6/BenchmarkTools/src/execution.jl:208[内联]
[11] benchmark_文件(::String)位于/home/oisov/Programming/Misc/Julia belaps/benchmark.jl:26
[12] 在./loading.jl:569中包含来自节点1(::字符串)的
[13] 在./sysimg.jl:14处包含(::字符串)
[14] 处理_选项(::Base.jl选项)位于./client.jl:305
[15] _start()位于./client.jl:371
在第36行开始的表达式中加载/home/oisov/Programming/Misc/Julia belaps/benchmark.jl时

println(@belapsed f())
更改为
println(@belapsed$f())
。我不能完全解释它,但

看到错误会有帮助吗?添加了错误消息我尝试构建一个MWE(或最小失败示例),但效果很好<代码>使用BenchmarkTools fname=“stackexchange46809845_f.jl”funstr=“”myfun()=rand(1000)”“open(fname,“w”)do f write(f,funstr)end include(fname)function_name=:myfun f=getfield(Main,function_name)@belapsed myfun()@belapsed f()@gggg是否尝试从邻居目录中包含它?是的,它对我仍然有效,你试过我的例子吗?以下是一个更新版本,以便于复制/粘贴。这很有魅力。非常感谢你的耐心!
0*10**(2**0)
4*10**(2**0) 
4*10**(2**1)
4*10**(2**2)
4*10**(2**3) 
4*10**(2**4) 
4*10**(2**5) 
4*10**(2**6) 
~/P/M/Julia-belaps ❯❯❯ julia benchmark.jl

9.495495495495496e-9
ERROR: LoadError: UndefVarError: f not defined
Stacktrace:
 [1] ##core#665() at /home/oisov/.julia/v0.6/BenchmarkTools/src/execution.jl:290
 [2] ##sample#666(::BenchmarkTools.Parameters) at /home/oisov/.julia/v0.6/BenchmarkTools/src/execution.jl:296
 [3] #_run#6(::Bool, ::String, ::Array{Any,1}, ::Function, ::BenchmarkTools.Benchmark{Symbol("##benchmark#664")}, ::BenchmarkTools.Parameters) at /home/oisov/.julia/v0.6/BenchmarkTools/src/execution.jl:324
 [4] (::BenchmarkTools.#kw##_run)(::Array{Any,1}, ::BenchmarkTools.#_run, ::BenchmarkTools.Benchmark{Symbol("##benchmark#664")}, ::BenchmarkTools.Parameters) at ./<missing>:0
 [5] anonymous at ./<missing>:?
 [6] #run_result#16(::Array{Any,1}, ::Function, ::BenchmarkTools.Benchmark{Symbol("##benchmark#664")}, ::BenchmarkTools.Parameters) at /home/oisov/.julia/v0.6/BenchmarkTools/src/execution.jl:40
 [7] (::BenchmarkTools.#kw##run_result)(::Array{Any,1}, ::BenchmarkTools.#run_result, ::BenchmarkTools.Benchmark{Symbol("##benchmark#664")}, ::BenchmarkTools.Parameters) at ./<missing>:0
 [8] #run#17(::Array{Any,1}, ::Function, ::BenchmarkTools.Benchmark{Symbol("##benchmark#664")}, ::BenchmarkTools.Parameters) at /home/oisov/.julia/v0.6/BenchmarkTools/src/execution.jl:43
 [9] (::Base.#kw##run)(::Array{Any,1}, ::Base.#run, ::BenchmarkTools.Benchmark{Symbol("##benchmark#664")}, ::BenchmarkTools.Parameters) at ./<missing>:0 (repeats 2 times)
 [10] macro expansion at /home/oisov/.julia/v0.6/BenchmarkTools/src/execution.jl:208 [inlined]
 [11] benchmark_files(::String) at /home/oisov/Programming/Misc/Julia-belaps/benchmark.jl:26
 [12] include_from_node1(::String) at ./loading.jl:569
 [13] include(::String) at ./sysimg.jl:14
 [14] process_options(::Base.JLOptions) at ./client.jl:305
 [15] _start() at ./client.jl:371
while loading /home/oisov/Programming/Misc/Julia-belaps/benchmark.jl, in expression starting on line 36