From 012c61878fb8c36990af6a34cadea01acf3b8880 Mon Sep 17 00:00:00 2001 From: Nathan Daly Date: Fri, 31 Jan 2025 10:13:54 -0700 Subject: [PATCH] FINALLY add a benchmark script. We should've had this from the beginning. (#39) * FINALLY add a benchmark script. We should've had this from the beginning. This is the status as of now: ```julia julia> include("bench/runbench.jl") 11.000 ns (0 allocations: 0 bytes) 61.641 ns (0 allocations: 0 bytes) 2.833 ns (0 allocations: 0 bytes) 15.489 ns (0 allocations: 0 bytes) 4.000 ns (0 allocations: 0 bytes) 26.104 ns (0 allocations: 0 bytes) 2.250 ns (0 allocations: 0 bytes) 2.291 ns (0 allocations: 0 bytes) 2.250 ns (0 allocations: 0 bytes) 2.250 ns (0 allocations: 0 bytes) 2.291 ns (0 allocations: 0 bytes) 2.291 ns (0 allocations: 0 bytes) 2.291 ns (0 allocations: 0 bytes) 2.291 ns (0 allocations: 0 bytes) 0 ``` (And here is the above benchmark run on v0.5.1 - when everything used `@generated` functions. You can see that we have recovered all of that performance.): ```julia julia> include("bench/runbench.jl") 10.844 ns (0 allocations: 0 bytes) 62.855 ns (0 allocations: 0 bytes) 3.041 ns (0 allocations: 0 bytes) 16.074 ns (0 allocations: 0 bytes) 4.416 ns (0 allocations: 0 bytes) 26.230 ns (0 allocations: 0 bytes) 2.833 ns (0 allocations: 0 bytes) 2.834 ns (0 allocations: 0 bytes) 2.916 ns (0 allocations: 0 bytes) 2.833 ns (0 allocations: 0 bytes) 2.833 ns (0 allocations: 0 bytes) 2.833 ns (0 allocations: 0 bytes) 2.833 ns (0 allocations: 0 bytes) 2.833 ns (0 allocations: 0 bytes) 0 ``` * Add compile time benchmarks --- bench/runbench.jl | 69 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 bench/runbench.jl diff --git a/bench/runbench.jl b/bench/runbench.jl new file mode 100644 index 0000000..1ebc164 --- /dev/null +++ b/bench/runbench.jl @@ -0,0 +1,69 @@ +using Blobs, BenchmarkTools + +@info "------- Benchmark Runtimes ---------" + +@eval struct MixedStruct10 + $((:($(Symbol("f$i"))::Float64) for i in 1:5)...) + $((:($(Symbol("x$i"))::Int64) for i in 1:5)...) +end +m10 = Blobs.malloc(MixedStruct10) + +@eval struct MixedStruct100 + $((:($(Symbol("f$i"))::Float64) for i in 1:50)...) + $((:($(Symbol("x$i"))::Int64) for i in 1:50)...) +end +m100 = Blobs.malloc(MixedStruct100) + +@btime Blobs.malloc(MixedStruct10) +@btime Blobs.malloc(MixedStruct100) + +@btime $(m10)[] +@btime $(m100)[] + +@btime $(m10)[] = $(m10[]) +@btime $(m100)[] = $(m100[]) + +@btime $(m10).x5[] +@btime $(m100).x5[] +@btime $(m100).x50[] + +@btime $(m10).f5[] = 0 +@btime $(m10).x5[] = 0 +@btime $(m100).f5[] = 0 +@btime $(m100).x5[] = 0 +@btime $(m100).x50[] = 0 + + +@info "------- Benchmark Compile Times ---------" + +# Benchmark Compile Times: +function eval_type(N) + S = gensym("MixedType$N") + @eval struct $S + $((:($(Symbol("f$i"))::Float64) for i in 1:(N÷2) )...) + $((:($(Symbol("x$i"))::Int64) for i in 1:(N÷2) )...) + end + return @eval($S) +end + +for N in (10,100) + @info " -- N = $N -- " + + @btime Blobs.malloc(S) setup=(S=eval_type($N)) + + @btime (Blobs.malloc(S))[] setup=(S=eval_type($N)) + + @btime (Blobs.malloc(S))[] = (Blobs.malloc(S)[]) setup=(S=eval_type($N)) + + @btime (Blobs.malloc(S)).x5[] setup=(S=eval_type($N)) + if N >= 100 + @btime (Blobs.malloc(S)).x50[] setup=(S=eval_type($N)) + end + + @btime (Blobs.malloc(S)).f5[] = 0 setup=(S=eval_type($N)) + @btime (Blobs.malloc(S)).x5[] = 0 setup=(S=eval_type($N)) + if N >= 100 + @btime (Blobs.malloc(S)).x50[] = 0 setup=(S=eval_type($N)) + end + +end