diff --git a/src/BaseBenchmarks.jl b/src/BaseBenchmarks.jl index b9676f3..87031aa 100644 --- a/src/BaseBenchmarks.jl +++ b/src/BaseBenchmarks.jl @@ -10,6 +10,7 @@ BenchmarkTools.DEFAULT_PARAMETERS.memory_tolerance = 0.01 const PARAMS_PATH = joinpath(dirname(@__FILE__), "..", "etc", "params.json") const SUITE = BenchmarkGroup() const MODULES = Dict("array" => :ArrayBenchmarks, + "alloc" => :AllocBenchmarks, "broadcast" => :BroadcastBenchmarks, "collection" => :CollectionBenchmarks, "dates" => :DatesBenchmarks, diff --git a/src/alloc/AllocBenchmarks.jl b/src/alloc/AllocBenchmarks.jl new file mode 100644 index 0000000..cb09b2d --- /dev/null +++ b/src/alloc/AllocBenchmarks.jl @@ -0,0 +1,60 @@ +module AllocBenchmarks + +using BenchmarkTools + +const SUITE = BenchmarkGroup() + +function perf_alloc_many_arrays() + for _ in 1:100 + # global to ensure that this is heap allocated + global a = [[] for _ in 1:1000] + + GC.safepoint() + Threads.atomic_fence() + end +end + +function perf_alloc_many_strings() + for i in 1:100 + # global to ensure that this is heap allocated + global b = ["hello $(j)" for j in 1:1000] + + GC.safepoint() + Threads.atomic_fence() + end +end + +# mutable to make it heap allocate +mutable struct Foo + x::Int + y::Int +end + +function perf_alloc_many_structs() + for i in 1:100 + # global to ensure that this is heap allocated + global b = [Foo(i, j) for j in 1:1000] + + GC.safepoint() + Threads.atomic_fence() + end +end + +function perf_grow_array() + global x = Vector{Int}() + for i in 1:100 + for j in 1:1000 + push!(x, j) + end + + GC.safepoint() + Threads.atomic_fence() + end +end + +SUITE["arrays"] = @benchmarkable perf_alloc_many_arrays() +SUITE["strings"] = @benchmarkable perf_alloc_many_strings() +SUITE["structs"] = @benchmarkable perf_alloc_many_structs() +SUITE["grow_array"] = @benchmarkable perf_grow_array() + +end # module