Skip to content

Commit

Permalink
update benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Barth committed Dec 17, 2021
1 parent 68e6396 commit 20ccc0b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
9 changes: 6 additions & 3 deletions test/perf/benchmark.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# run as, e.g.
#
# julia benchmark.jl 3 sparse
using JSON


Expand Down Expand Up @@ -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)`,
Expand Down
21 changes: 13 additions & 8 deletions test/perf/test_2dvar_benchmark.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand All @@ -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]
Expand All @@ -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)
Expand Down

0 comments on commit 20ccc0b

Please sign in to comment.