From ac1826cc3a0210cc1870ade3cd01d1484d64f338 Mon Sep 17 00:00:00 2001 From: Mo8it Date: Tue, 5 Apr 2022 03:11:53 +0200 Subject: [PATCH] Seperate profiling and benchmarking --- performance/Benchmark.jl | 50 ++++++++++++++++++++++++++++++++++++++++ performance/Project.toml | 5 ++++ 2 files changed, 55 insertions(+) create mode 100644 performance/Benchmark.jl create mode 100644 performance/Project.toml diff --git a/performance/Benchmark.jl b/performance/Benchmark.jl new file mode 100644 index 0000000..8866335 --- /dev/null +++ b/performance/Benchmark.jl @@ -0,0 +1,50 @@ +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 diff --git a/performance/Project.toml b/performance/Project.toml new file mode 100644 index 0000000..f99617e --- /dev/null +++ b/performance/Project.toml @@ -0,0 +1,5 @@ +[deps] +BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" +Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" +ProfileView = "c46f51b8-102a-5cf2-8d2c-8597cb0e0da7" +ReCo = "b25f7548-fcc9-4c91-bc24-841b54f4dd54"