2017-10-18 18 views
1

Présentation


J'ai un répertoire avec la structure suivanteBenchmarktools' belapsed ne fonctionne pas sur le symbole

--> 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 

Je cherche à itérer sur tous les fichiers Julia et référence les contre les données d'étalonnage situé dans le répertoire supérieur Benchmark. Je ne veux pas avoir cd dans chaque répertoire et exécuter @ belapsed de la ligne de commande de julia pour chronométrer chaque fonction individuellement.

Pour résoudre ce problème, j'ai écrit le code suivant qui est censé être situé sous benchmarks dans la hierarchie ci-dessus. Cependant, je l'ai fait légèrement plus simple à des fins d'illustration.

Tentative de solution


EDIT: Le code ci-dessous ne suit pas la hiérarchie décrite ci-dessus. Pour reproduire rapidement l'erreur, le code ci-dessous a été écrit de telle sorte que tous les fichiers peuvent être placés dans le même répertoire.

benchmark.jl

include("PE_002.jl") 

using BenchmarkTools 

function get_file_path(PE=1) 
    current_folder = pwd() 
    PE_folder = "/PE_" * lpad(string(PE),3,"0") 
    dirname(pwd()) * "/Problems" * PE_folder * "/Julia" 
end 


function include_files(PE_dir) 
    for filename in readdir(PE_dir) 
     if !startswith(filename, "benchmark") 
      filepath = PE_dir * "/" * filename 
      @everywhere include($filepath) 
     end 
    end 
end 


function benchmark_files(PE_dir) 
    for filename in readdir(PE_dir) 
     if !startswith(filename, "benchmark") 
      f = getfield(Main, Symbol(filename[1:end-3])) 
      # Produces an error 
      println(@belapsed f()) 
     end 
    end 
end 

# Works 
println(@belapsed PE_002()) 

PE_dir = pwd() 
include_files(PE_dir) 
benchmark_files(PE_dir) 

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_naive.jl

function PE_002_naive(limit=4 * 10^6, F_1=1, F_2=2) 
    total = 0 
    while F_2 < limit 
     if F_2 % 2 == 0 
      total += F_2 
     end 
     F_1, F_2 = F_2, F_1 + F_2 
    end 
    total 
end 

test_001.txt

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) 

Question

assez intéressant de noter que le fichier y compris PE_002 et en cours d'exécution puis @ belapsed travaux, mais l'obtention du nom de fichier à partir du répertoire, le transformant en un symbole, puis en essayant de le chronométrer avec @belapsed échoue.

Je sais @elapsed works, cependant, en raison de la collecte des ordures, il n'est pas assez précis pour mes besoins.

Existe-t-il un moyen simple de comparer tous les fichiers d'un répertoire distant à l'aide de BenchmarkTools ou d'outils similaires?

Tout ce dont j'ai besoin est un nombre unique représentant la durée moyenne/moyenne de chaque fichier.

EDIT 2: Par demande J'ai inclus le message d'erreur complet ci-dessous

~/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 
+0

Soyez utile pour voir l'erreur? –

+0

Ajout d'un message d'erreur – N3buchadnezzar

+0

J'ai essayé de créer un MWE (ou un exemple de défaillance minimale), mais cela fonctionne correctement. '' 'L'aide BenchmarkTools fname = "stackexchange46809845_f.jl" funstr = "" "myfun() = rand (1000)" "" ouverte (fname, "w") faire f écriture (f, funstr) fin Include (FNAME) nom_fonction =: myfun f = getfield (principal, function_name) @belapsed myfun() @belapsed f() '' ' – gggg

Répondre