Skip to content

Commit 065fc5c

Browse files
authored
Merge pull request #33 from JuliaCI/misc
add miscellaneous benchmarks from various issues
2 parents 7584a46 + 5686dd6 commit 065fc5c

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

src/BaseBenchmarks.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const MODULES = Dict("array" => :ArrayBenchmarks,
1818
"io" => :IOBenchmarks,
1919
"linalg" => :LinAlgBenchmarks,
2020
"micro" => :MicroBenchmarks,
21+
"misc" => :MiscellaneousBenchmarks,
2122
"nullable" => :NullableBenchmarks,
2223
"parallel" => :ParallelBenchmarks,
2324
"problem" => :ProblemBenchmarks,

src/misc/MiscellaneousBenchmarks.jl

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
module MiscellaneousBenchmarks
2+
3+
include(joinpath(dirname(@__FILE__), "..", "utils", "RandUtils.jl"))
4+
5+
using .RandUtils
6+
using BenchmarkTools
7+
using Compat
8+
9+
const SUITE = BenchmarkGroup()
10+
11+
###########################################################################
12+
# Splatting penalties (issue #13359)
13+
14+
g = addgroup!(SUITE, "splatting", ["array", "getindex"])
15+
16+
@noinline function perf_splatting_(A, xs...)
17+
A[xs...]
18+
end
19+
function perf_splatting(A, n, xs...)
20+
s = zero(eltype(A))
21+
for i = 1:n
22+
s += perf_splatting_(A, xs...)
23+
end
24+
return s
25+
end
26+
27+
g[(3,3,3)] = @benchmarkable perf_splatting($(samerand(3,3,3)), 100, 1, 2, 3)
28+
29+
###########################################################################
30+
# crossover from x + y + ... to afoldl (issue #13724)
31+
32+
function perf_afoldl(n, k)
33+
s = zero(eltype(k))
34+
assert(length(k) >= 12)
35+
for i = 1:n
36+
s += k[1] + k[2] + k[3] + k[4] + k[5] + 2 * k[6] + k[7] + k[8] + k[9] + k[10] + k[11] + k[12]
37+
end
38+
return s
39+
end
40+
41+
g = addgroup!(SUITE, "afoldl", ["+", "getindex"])
42+
g["Int"] = @benchmarkable perf_afoldl(100, $(zeros(Int, 20)))
43+
g["Float64"] = @benchmarkable perf_afoldl(100, $(zeros(Float64, 20)))
44+
g["Complex{Float64}"] = @benchmarkable perf_afoldl(100, $(zeros(Complex{Float64}, 20)))
45+
46+
###########################################################################
47+
# repeat function (issue #15553)
48+
49+
g = addgroup!(SUITE, "repeat", ["array"])
50+
g[200, 24, 1] = @benchmarkable repeat($(collect(1:200)), inner=$[24], outer=$[1])
51+
g[200, 1, 24] = @benchmarkable repeat($(collect(1:200)), inner=$[1], outer=$[24])
52+
53+
###########################################################################
54+
# bitshift operators (from #18135)
55+
56+
function perf_bitshift(r, n)
57+
s = zero(eltype(r))
58+
for i in r
59+
s += i<<n
60+
end
61+
return s
62+
end
63+
64+
g = addgroup!(SUITE, "bitshift", ["range"])
65+
g["Int", "Int"] = @benchmarkable perf_bitshift($(1:1000), Int(3))
66+
g["Int", "UInt"] = @benchmarkable perf_bitshift($(1:1000), UInt(3))
67+
g["UInt", "UInt"] = @benchmarkable perf_bitshift($(UInt(1):UInt(1000)), UInt(3))
68+
g["UInt32", "UInt32"] = @benchmarkable perf_bitshift($(UInt32(1):UInt32(1000)), UInt32(3))
69+
70+
###########################################################################
71+
# Integer, Float64, and Date (#18000) parsing
72+
73+
if !method_exists(parse, Tuple{Type{DateTime}, AbstractString})
74+
Base.parse(::Type{DateTime}, s::AbstractString) = DateTime(s)
75+
end
76+
77+
function perf_parse{T}(result::AbstractVector{T}, strings::AbstractVector)
78+
assert(length(result) == length(strings))
79+
for i = 1:length(strings)
80+
@inbounds result[i] = parse(T, strings[i])
81+
end
82+
return result
83+
end
84+
85+
g = addgroup!(SUITE, "parse", ["DateTime"])
86+
datestr = map(string,range(DateTime("2016-02-19T12:34:56"),Dates.Millisecond(123),200))
87+
g["DateTime"] = @benchmarkable perf_parse($(similar(datestr, DateTime)), $datestr)
88+
g["Int"] = @benchmarkable perf_parse($(Array(Int,1000)), $(map(string, 1:1000)))
89+
g["Float64"] = @benchmarkable perf_parse($(Array(Float64,1000)), $(map(string, 1:1000)))
90+
91+
###########################################################################
92+
93+
end

0 commit comments

Comments
 (0)