Skip to content

Commit

Permalink
add more regression benchmark tests (#233)
Browse files Browse the repository at this point in the history
* add more regression benchmark tests

* repeat char does not exist in 0.6
  • Loading branch information
KristofferC authored Oct 16, 2018
1 parent 489d6b6 commit 08baef1
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/broadcast/BroadcastBenchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,22 @@ for t in (t1, t2, t3)
g[length(t), "scal_tup_x3"] = @benchmarkable broadcast(+, 1, $t, 1, $t, 1, $t)
end

###########################################################################

xset= 10:15
yset= 12:14
f(x,y) = sqrt( x^2 + y^2 )

function perf_loop3(xset, yset)
m = Matrix{Float64}(undef, 3, length(xset)*length(yset))
i = 1
@inbounds for x in xset, y in yset
m[:,i] .= (Float64(x), Float64(y), f(x,y))
i += 1
end
return m
end

SUITE["26942"] = @benchmarkable perf_loop3($xset, $yset)

end # module
7 changes: 7 additions & 0 deletions src/linalg/LinAlgBenchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,11 @@ for b in values(g)
b.params.time_tolerance = 0.40
end

#############
# small exp #
#############

SUITE["small exp #29116"] = @benchmarkable exp([1. 0; 2 0])


end # module
85 changes: 85 additions & 0 deletions src/misc/MiscellaneousBenchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -305,4 +305,89 @@ for N in (1,1000), M in 1:4
g["zip($(join(fill("1:$N", M), ", ")))"] = @benchmarkable collect($X)
end

####################################################
# Allocation elision stumped by conditional #28226 #
# Note, not fixed when this benchmark was written #
####################################################

function perf_colwise_alloc!(r, a, b)
@inbounds for j = 1:size(a,2)
r[j] = evaluate_cond(view(a, :, j), view(b, :, j))
end
r
end

@inline function evaluate_cond(a, b)
length(a) == 0 && return 0.0 # comment out and 0.7 is super fast
@inbounds begin
s = 0.0
@simd for I in eachindex(a, b)
ai = a[I]
bi = b[I]
s += abs2(ai - bi)
end
return s
end
end

function perf_colwise_noalloc!(r, a, b)
@inbounds for j = 1:size(a,2)
r[j] = evaluate_nocond(view(a, :, j), view(b, :, j))
end
r
end

@inline function evaluate_nocond(a, b)
@inbounds begin
s = 0.0
@simd for I in eachindex(a, b)
ai = a[I]
bi = b[I]
s += abs2(ai - bi)
end
return s
end
end

z = zeros(41); A = rand(2, 41); B = rand(2, 41);
g = addgroup!(SUITE, "allocation elision view")
g["conditional"] = @benchmarkable perf_colwise_alloc!($z, $A, $B)
g["no conditional"] = @benchmarkable perf_colwise_noalloc!($z, $A, $B)


####################################################
# Fastmath infererence large number of args #22275 #
####################################################

function f2(a,b,c,d,e,f,g,h,j,k,l,m,n,o,p)
aidx = eachindex(a)
@fastmath for i in aidx
@inbounds a[i] = b[i]+c*(d*e[i]+f*g[i]+h*j[i]+k*l[i]+m*n[i]+o*p[i])
end
end
a = rand(10)
b = rand(10)
c = 0.1
d = 0.1
e = rand(10)
f = 0.1
g = rand(10)
h = 0.1
j = rand(10)
k = 0.1
l = rand(10)
m = 0.1
n = rand(10)
o = 0.1
p = rand(10)

SUITE["fastmath many args"] = @benchmarkable f2($a,$b,$c,$d,$e,$f,$g,$h,$j,$k,$l,$m,$n,$o,$p)

##############################################################
# Performance and typing of 6+ dimensional generators #21058 #
##############################################################
perf_g6() = sum([+(a,b,c,d,e,f) for a in 1:4, b in 1:4, c in 1:4, d in 1:4, e in 1:4, f in 1:4])

SUITE["perf highdim generator"] = @benchmarkable perf_g6()

end
19 changes: 17 additions & 2 deletions src/sparse/SparseBenchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ for (om, ok, on) in (# order of matmul dimensions m, k, and n
g["A_mul_Bt", "dense $(m)x$(k), sparse $(n)x$(k) -> dense $(m)x$(n)"] = @benchmarkable A_mul_Bt($densemat, $tsparsemat)
g["At_mul_B", "dense $(k)x$(m), sparse $(k)x$(n) -> dense $(m)x$(n)"] = @benchmarkable At_mul_B($tdensemat, $sparsemat)
g["At_mul_Bt", "dense $(k)x$(m), sparse $(n)x$(k) -> dense $(m)x$(n)"] = @benchmarkable At_mul_Bt($tdensemat, $tsparsemat)
end
end
# in-place dense-sparse -> dense ops, transpose variants, i.e. A[t]_mul[t]!(dense, dense, sparse)
m, k, n, destmat, densemat, sparsemat, tdensemat, tsparsemat = allocmats_ds(om, ok, on, 4, 12, Float64)
if VERSION >= v"0.7.0-DEV.3204"
Expand All @@ -282,7 +282,7 @@ for (om, ok, on) in (# order of matmul dimensions m, k, and n
g["A_mul_Bc", "dense $(m)x$(k), sparse $(n)x$(k) -> dense $(m)x$(n)"] = @benchmarkable A_mul_Bc($densemat, $tsparsemat)
g["Ac_mul_B", "dense $(k)x$(m), sparse $(k)x$(n) -> dense $(m)x$(n)"] = @benchmarkable Ac_mul_B($tdensemat, $sparsemat)
g["Ac_mul_Bc", "dense $(k)x$(m), sparse $(n)x$(k) -> dense $(m)x$(n)"] = @benchmarkable Ac_mul_Bc($tdensemat, $tsparsemat)
end
end
# in-place dense-sparse -> dense ops, adjoint variants, i.e. A[c]_mul[c]!(dense, dense, sparse)
m, k, n, destmat, densemat, sparsemat, tdensemat, tsparsemat = allocmats_ds(om, ok, on, 2, 8, Complex{Float64})
if VERSION >= v"0.7.0-DEV.3204"
Expand Down Expand Up @@ -355,4 +355,19 @@ for b in values(g)
b.params.time_tolerance = 0.3
end


#################
# sparse matvec #
#################
g = addgroup!(SUITE, "sparse matvec")
B = randn(100000, 100)
A = sprand(100000, 100000, 0.00001)
if VERSION >= v"0.7.0-DEV.3204"
g["non-adjoint"] = @benchmarkable A * B
g["adjoint"] = @benchmarkable A' * B
else
g["non-adjoint"] = @benchmarkable A * B
g["adjoint"] = @benchmarkable At_mul_B(A, B)
end

end # module
12 changes: 12 additions & 0 deletions src/string/StringBenchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,16 @@ buffer = IOBuffer(("bar" ^ 20000) * "ians")
target = ("bar" ^ 300) * "ian"
g["barbarian backtrack"] = @benchmarkable readuntil(seekstart($buffer), $target)

#################
# repeat #22462 #
#################

g = addgroup!(SUITE, "repeat")
g["repeat str len 1"] = @benchmarkable repeat(" ", 500)
g["repeat str len 16"] = @benchmarkable repeat("repeatmerepeatme", 500)
if VERSION >= v"v0.7"
g["repeat char 1"] = @benchmarkable repeat(' ', 500)
g["repeat char 2"] = @benchmarkable repeat('α', 500)
end

end # module

0 comments on commit 08baef1

Please sign in to comment.