Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add simple allocation benchmarks #291

Merged
merged 7 commits into from
Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/BaseBenchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
60 changes: 60 additions & 0 deletions src/alloc/AllocBenchmarks.jl
Original file line number Diff line number Diff line change
@@ -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()
vilterp marked this conversation as resolved.
Show resolved Hide resolved
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