From 20ccc0b6cf35821ee0538a57f634950b7502afb4 Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Fri, 17 Dec 2021 12:53:22 +0100 Subject: [PATCH] update benchmark --- test/perf/benchmark.jl | 9 ++++++--- test/perf/test_2dvar_benchmark.jl | 21 +++++++++++++-------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/test/perf/benchmark.jl b/test/perf/benchmark.jl index e77517bb..0000d63a 100644 --- a/test/perf/benchmark.jl +++ b/test/perf/benchmark.jl @@ -1,3 +1,6 @@ +# run as, e.g. +# +# julia benchmark.jl 3 sparse using JSON @@ -33,11 +36,11 @@ for i = 1:length(sizes) # must be one line otherwise the result of time -v is too difficult to parse if method == "sparse" - cmd = "using DIVAnd; using JSON; include(\"test_2dvar_benchmark.jl\"); print(JSON.json(benchmark_nd_repeat($(ndim),$(sizes[i]),10; operatortype=Val{:sparse})))" + cmd = "include(\"test_2dvar_benchmark.jl\"); print(JSON.json(benchmark_nd_repeat($(ndim),$(sizes[i]),10; operatortype=Val{:sparse})))" elseif method == "varanalysis" - cmd = "using DIVAnd; using JSON; include(\"test_2dvar_benchmark.jl\"); print(JSON.json(benchmark_nd_repeat($(ndim),$(sizes[i]),5; tol = 1e-3)))" + cmd = "include(\"test_2dvar_benchmark.jl\"); print(JSON.json(benchmark_nd_repeat($(ndim),$(sizes[i]),5; tol = 1e-3)))" else - cmd = "using DIVAnd; using JSON; include(\"test_2dvar_benchmark.jl\"); print(JSON.json(benchmark_nd_repeat($(ndim),$(sizes[i]),5; inversion=:pcg, operatortype=Val{:MatFun}, tol=1e-3, maxit = 100000)))" + cmd = "include(\"test_2dvar_benchmark.jl\"); print(JSON.json(benchmark_nd_repeat($(ndim),$(sizes[i]),5; inversion=:pcg, operatortype=Val{:MatFun}, tol=1e-3, maxit = 100000)))" end run(pipeline( `/usr/bin/time -v $(juliaexec) --eval $(cmd)`, diff --git a/test/perf/test_2dvar_benchmark.jl b/test/perf/test_2dvar_benchmark.jl index fbbac631..0f1adbbf 100644 --- a/test/perf/test_2dvar_benchmark.jl +++ b/test/perf/test_2dvar_benchmark.jl @@ -22,6 +22,11 @@ # Alexander Barth # GPLv2 or later +using DIVAnd +using JSON +using Printf +using Statistics + function test_2dvar_benchmark(name) @printf("Running DIVAnd benchmark in 2 dimensions\n") @@ -51,9 +56,9 @@ function test_2dvar_benchmark(name) @printf("size %5d time %10.4f \n", ng[i], median_time[i]) end - fname = "test_2dvar_benchmark_$(name).mat" - @printf("save result in file %s\n", fname) - matwrite(fname, Dict("time" => time, "RMS" => RMS, "ng" => ng)) + #fname = "test_2dvar_benchmark_$(name).mat" + #@printf("save result in file %s\n", fname) + #matwrite(fname, Dict("time" => time, "RMS" => RMS, "ng" => ng)) return median_time, ng, time end @@ -68,7 +73,7 @@ function benchmark_nd_repeat(n, ng, ntimes; kwargs...) times[i], RMS[i] = benchmark_nd(n, ng; kwargs...) end - mad(x) = median(abs.(x - median(x))) + mad(x) = median(abs.(x .- median(x))) stat = Dict{String,Any}([ (string(f), f(times)) for f in [mean, std, median, mad, minimum, maximum] @@ -89,16 +94,16 @@ function benchmark_nd(n, ng; kwargs...) f(xy...) = .*([cos.(2 * pi * ng * x / 20) for x in xy]...) # grid of background field - mask, pmn, xyi = DIVAnd_squaredom(n, linspace(0, 1, ng)) + mask, pmn, xyi = DIVAnd_squaredom(n, LinRange(0, 1, ng)) vi = f(xyi...) # grid of observations - xy = ndgrid([linspace(1e-6, 1 - 1e-6, mg) for i = 1:n]...) + xy = ndgrid([LinRange(1e-6, 1 - 1e-6, mg) for i = 1:n]...) v = f([x[:] for x in xy]...) t1 = time_ns() - va, s = varanalysis(mask, pmn, xyi, xy, v, len, epsilon2; kwargs...) - #va,s = DIVAndrun(mask,pmn,xyi,xy,v,len,epsilon2; kwargs...); + #va, s = varanalysis(mask, pmn, xyi, xy, v, len, epsilon2; kwargs...) + va,s = DIVAndrun(mask,pmn,xyi,xy,v,len,epsilon2; kwargs...); t2 = time_ns() time = (t2 - t1) / 1e9 RMS = rms(va, vi)