mirror of
https://gitlab.rlp.net/mobitar/ReCo.jl.git
synced 2024-11-08 22:21:08 +00:00
51 lines
1.2 KiB
Julia
51 lines
1.2 KiB
Julia
|
module Benchmark
|
||
|
|
||
|
using Dates: Dates
|
||
|
using BenchmarkTools: @benchmark
|
||
|
|
||
|
# TODO: Replace JSON3
|
||
|
# FIX: Benchmarking
|
||
|
|
||
|
using ReCo
|
||
|
|
||
|
function run_benchmarks(
|
||
|
dir::String = "";
|
||
|
n_particles::Int64 = 1000,
|
||
|
v₀::Float64 = 20.0,
|
||
|
duration::Float64 = 2.0,
|
||
|
n_bundle_snapshots::Int64 = 0,
|
||
|
comment = ""
|
||
|
)
|
||
|
if length(dir) == 0
|
||
|
dir = init_sim(; n_particles = n_particles, v₀ = v₀, parent_dir = "benchmark")
|
||
|
end
|
||
|
|
||
|
benchmark = @benchmark run_sim(
|
||
|
$dir; duration = $duration, n_bundle_snapshots = $n_bundle_snapshots
|
||
|
)
|
||
|
|
||
|
display(benchmark)
|
||
|
|
||
|
open("exports/benchmark.txt", "a+") do f
|
||
|
JSON3.pretty(
|
||
|
f,
|
||
|
Dict(
|
||
|
"n_particles" => n_particles,
|
||
|
"v₀" => v₀,
|
||
|
"duration" => duration,
|
||
|
"n_bundle_snapshots" => n_bundle_snapshots,
|
||
|
"comment" => comment,
|
||
|
"datetime" => Dates.now(),
|
||
|
"mean_time/ns" => mean(benchmark.times),
|
||
|
"allocs" => benchmark.allocs,
|
||
|
"memory" => benchmark.memory,
|
||
|
),
|
||
|
)
|
||
|
write(f, "\n")
|
||
|
end
|
||
|
|
||
|
return dir
|
||
|
end
|
||
|
|
||
|
end # module
|