-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathbenchmarks.jl
54 lines (42 loc) · 1.42 KB
/
benchmarks.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using BenchmarkTools
using KernelFunctions
N1 = 10
N2 = 20
X = rand(N1, N2)
Xc = ColVecs(X)
Xr = RowVecs(X)
Xv = collect.(eachcol(X))
Y = rand(N1, N2)
Yc = ColVecs(Y)
Yr = RowVecs(Y)
Yv = collect.(eachcol(Y))
# Create the general suite of benchmarks
SUITE = BenchmarkGroup()
kernels = Dict(
"SqExponential" => SqExponentialKernel(), "Exponential" => ExponentialKernel()
)
inputtypes = Dict("ColVecs" => (Xc, Yc), "RowVecs" => (Xr, Yr), "Vecs" => (Xv, Yv))
functions = Dict(
"kernelmatrixX" => (kernel, X, Y) -> invoke(kernelmatrix, Tuple{kernel, Any}, kernel, X),
"kernelmatrixXY" => (kernel, X, Y) -> kernelmatrix(kernel, X, Y),
"kernelmatrix_diagX" => (kernel, X, Y) -> kernelmatrix_diag(kernel, X),
"kernelmatrix_diagXY" => (kernel, X, Y) -> kernelmatrix_diag(kernel, X, Y),
)
for (kname, kernel) in kernels
SUITE[kname] = sk = BenchmarkGroup()
for (inputname, (X, Y)) in inputtypes
sk[inputname] = si = BenchmarkGroup()
for (fname, f) in functions
si[fname] = @benchmarkable $f($kernel, $X, $Y)
end
end
end
# Uncomment the following to run benchmark locally
tune!(SUITE)
results = run(SUITE, verbose=true)
Xc = ColVecs(rand(2, 2000))
k = SqExponentialKernel()
@which kernelmatrix(k, Xc)
@btime kernelmatrix($k, $Xc);
@btime invoke(kernelmatrix, Tuple{KernelFunctions.SimpleKernel, $typeof(Xc)}, $k, $Xc);
# @btime invoke(kernelmatrix, Tuple{Kernel, $typeof(Xc)}, $k, $Xc);