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 tuple sum benchmarks #7

Merged
merged 1 commit into from
Feb 29, 2016
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 @@ -23,6 +23,7 @@ include("shootout/ShootoutBenchmarks.jl")
include("sort/SortBenchmarks.jl")
include("sparse/SparseBenchmarks.jl")
include("string/StringBenchmarks.jl")
include("tuples/TupleBenchmarks.jl")

macro execute(tagpred)
return esc(quote
Expand Down
53 changes: 53 additions & 0 deletions src/tuples/TupleBenchmarks.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
module TupleBenchmarks

import ..BaseBenchmarks
using ..BenchmarkTrackers
using ..RandUtils


###############
# issue #5274 #
###############

immutable TupleWrapper{N, T}
data::NTuple{N, T}
end

Base.eltype{N,T}(::TupleWrapper{N,T}) = T
Base.length{N,T}(::TupleWrapper{N,T}) = N

function get_index(n::NTuple, i::Int)
@inbounds v = n[i]
return v
end

function get_index(n::TupleWrapper, i::Int)
@inbounds v = n.data[i]
return v
end

function sum_tuple{N, T}(n::Union{NTuple{N, T}, TupleWrapper{N, T}})
s = zero(T)
for i in 1:N
s += get_index(n, i)
end
return s
end


TUPLE_SUM_SIZES = (3, 8, 30, 60)
TUPLE_SUM_TYPES = (Float32, Float64)

@track BaseBenchmarks.TRACKER "tuple indexing" begin
@setup begin
tuples = [((samerand(T, i)...)) for i in TUPLE_SUM_SIZES, T in TUPLE_SUM_TYPES]
tuple_wrappers = [TupleWrapper((samerand(T, i)...)) for i in TUPLE_SUM_SIZES, T in TUPLE_SUM_TYPES]
end
@benchmarks begin
[(:sumelt, "TupleWrapper", length(t_wrap), eltype(t_wrap)) => sum_tuple(t_wrap) for t_wrap in tuple_wrappers]
[(:sumelt, "NTuple", length(t), eltype(t)) => sum_tuple(t) for t in tuples]
end
@tags "tuple" "indexing" "sum"
end

end # module