-
Notifications
You must be signed in to change notification settings - Fork 126
/
benchmark_matrices.jl
119 lines (94 loc) · 2.3 KB
/
benchmark_matrices.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
module benchmark_matrices
using BenchmarkTools
using Oscar
const reps = 10
# benchmark: matrix addition
function test_add(a)
s = a
for i = 1:reps
s += a
end
return s
end
# benchmark: matrix multiplication
function test_mul(a)
s = a
for i = 1:reps
s *= a
end
return s
end
# TODO: test_inv
# benchmark: min poly
function test_minpoly(a)
s = minpoly(a)
for i = 1:reps
s += minpoly(a)
end
return s
end
# benchmark: char poly
function test_charpoly(a)
s = charpoly(a)
for i = 1:reps
s += charpoly(a)
end
return s
end
# benchmark: order computation
# TODO: not even implemented for most of our matrix types
function test_order(a)
s = order(a)
for i = 1:reps
s += order(a)
end
return s
end
# HACK HACK HACK
function Base.:+(x::Oscar.GAPGroupElem, y::Oscar.GAPGroupElem)
return Oscar.group_element(parent(x), x.X+y.X)
end
# test data
# TODO: do something better than using identity matrix!!
# e.g. a "random" dense matrix; ideally invertible so that we
# can we can try inversion, too
n = 10 # 10 x 10 matrices: TODO: test with a range of different degrees
testdata = Dict{String,Any}()
for (p,d) in [(2,1), (17,1), (17,2)]
q = p^d
mats = Dict{String,Any}()
mats["GAP GF($p,$d)"] = one(GL(n,q))
mats["raw GAP GF($p,$d)"] = one(GL(n,q)).X
mats["GF($p,$d)"] = identity_matrix(GF(p,d), n)
mats["GF(fmpz($p),$d)"] = identity_matrix(GF(fmpz(p),d), n)
if d == 1
mats["Oscar GF($p)"] = identity_matrix(GF(p), n)
mats["Oscar GF(fmpz($p))"] = identity_matrix(GF(fmpz(p)), n)
end
testdata["GF($p,$d)"] = mats
end
testdata["ZZ or QQ"] = Dict{String,Any}(
"GAP ZZ" => GAP.Globals.IdentityMat(n),
"Oscar ZZ" => identity_matrix(ZZ, n),
"Oscar QQ" => identity_matrix(QQ, n),
)
suite = BenchmarkGroup()
for f in [test_add, test_mul]
#for f in [test_add, test_mul, test_minpoly, test_charpoly, test_order]
println(nameof(f))
s = suite[nameof(f)] = BenchmarkGroup()
for (ring, mats) in testdata
s[ring] = BenchmarkGroup()
for (desc, x) in mats
#println(" input: ", desc)
s[ring][desc] = @benchmarkable $(f)($x) # seconds=1
f(x) # make sure it actually runs
end
end
end
end # module
#=
suite = benchmark_matrices.suite;
tune!(suite)
results = run(suite, verbose = true)
=#