From 10018160e299f569092367ec498cf7d6acb1547f Mon Sep 17 00:00:00 2001 From: MoBit Date: Fri, 26 Nov 2021 03:35:39 +0100 Subject: [PATCH] benchmarks --- src/Particle.jl | 5 +++-- src/PreVector.jl | 2 +- src/ReCo.jl | 5 +++-- src/benchmark.jl | 24 +++++++++++++++++++++++- src/simulation.jl | 6 +++--- 5 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/Particle.jl b/src/Particle.jl index 6563d3c..5267825 100644 --- a/src/Particle.jl +++ b/src/Particle.jl @@ -1,12 +1,13 @@ mutable struct Particle id::Int64 + c::Vector{Float64} # Center tmp_c::Vector{Float64} # Temporary center φ::Float64 # Angle - function Particle(; id::Int64, c::SVector{2,Float64}, φ::Float64) - return new(id, c, c, φ) + function Particle(; id::Int64, c::Vector{Float64}, φ::Float64) + return new(id, c, copy(c), φ) end end diff --git a/src/PreVector.jl b/src/PreVector.jl index 6c3a58c..db7a10d 100644 --- a/src/PreVector.jl +++ b/src/PreVector.jl @@ -2,7 +2,7 @@ mutable struct PreVector{T} last_ind::UInt64 v::Vector{T} - PreVector(T, N) = new{T}(UInt64(0), Vector{T}(undef, N)) + PreVector{T}(N) where {T} = new{T}(UInt64(0), Vector{T}(undef, N)) end function push!(pv::PreVector{T}, x::T) where {T} diff --git a/src/ReCo.jl b/src/ReCo.jl index d630980..c0525a2 100644 --- a/src/ReCo.jl +++ b/src/ReCo.jl @@ -10,11 +10,12 @@ using JLD2: JLD2 using JSON3: JSON3 import Dates: now, CompoundPeriod, canonicalize -import Base: push!, run, iterate +import Base: push!, iterate -# Development deps +# BEGIN dev deps using Revise using BenchmarkTools +# END set_theme!(theme_black()) diff --git a/src/benchmark.jl b/src/benchmark.jl index ebe163e..3189691 100644 --- a/src/benchmark.jl +++ b/src/benchmark.jl @@ -1 +1,23 @@ -using BenchmarkTools +function run_benchmarks() + benchmark_exprs = [:(run_sim(; N=1000, T=5, v=20.0, snapshot_at=0.1, save_data=false))] + + for expr in benchmark_exprs + benchmark = @benchmark eval(expr) + + display(benchmark) + + open("benchmark.txt", "a+") do f + json = JSON3.pretty( + Dict( + "benchmark" => repr(expr), + "datetime" => now(), + "mean_time/ns" => mean(benchmark.times), + "allocs" => benchmark.allocs, + "memory" => benchmark.memory, + ), + ) + + write(f, json) + end + end +end \ No newline at end of file diff --git a/src/simulation.jl b/src/simulation.jl index b35f897..64884d1 100644 --- a/src/simulation.jl +++ b/src/simulation.jl @@ -37,10 +37,10 @@ function euler!(args) c = args.c₁ / (distance²^4) * (args.c₂ / (distance²^3) - 1) @turbo for k in 1:2 - dck = c * r⃗₁₂[k] + dc = c * r⃗₁₂[k] - p.tmp_c[k] -= dck - p2.tmp_c[k] += dck + p.tmp_c[k] -= dc + p2.tmp_c[k] += dc end end end