Skip to content

Commit 1d8703c

Browse files
committed
Add matrixobj creation benchmark
... based on old MatrixObj benchmarks I wrote years ago. I think it's useful to also have the benchmarks (including the old ones) permanently in the repo, so that we can measure for regressions and also create new benchmarks more easily.
1 parent 81963ee commit 1d8703c

File tree

3 files changed

+420
-0
lines changed

3 files changed

+420
-0
lines changed
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
ReadGapRoot("benchmark/matobj/bench.g");
2+
3+
4+
TestReadingMatrix := function(m)
5+
local f;
6+
7+
PrintHeadline("m[i][j]");
8+
MyBench(function()
9+
local u, i, j, rows, cols, x;
10+
rows := [1..Length(m)];
11+
cols := [1..Length(m[1])];
12+
for u in [1..QuoInt(100000,Length(m)*Length(m[1]))] do
13+
for i in rows do
14+
for j in cols do
15+
x:=m[i][j];
16+
od;
17+
od;
18+
od;
19+
end);
20+
21+
PrintHeadline("m[i,j]");
22+
MyBench(function()
23+
local u, i, j, rows, cols, x;
24+
rows := [1..Length(m)];
25+
cols := [1..Length(m[1])];
26+
for u in [1..QuoInt(100000,Length(m)*Length(m[1]))] do
27+
for i in rows do
28+
for j in cols do
29+
x:=m[i,j];
30+
od;
31+
od;
32+
od;
33+
end);
34+
35+
PrintHeadline("MatElm(m,i,j)");
36+
MyBench(function()
37+
local u, i, j, rows, cols, x;
38+
rows := [1..Length(m)];
39+
cols := [1..Length(m[1])];
40+
for u in [1..QuoInt(100000,Length(m)*Length(m[1]))] do
41+
for i in rows do
42+
for j in cols do
43+
x:=MatElm(m,i,j);
44+
od;
45+
od;
46+
od;
47+
end);
48+
49+
PrintHeadline("MatElm(m,i,j) with prefetched method");
50+
f:=ApplicableMethod(MatElm, [m,1,1]);;
51+
MyBench(function()
52+
local u, i, j, rows, cols, x;
53+
rows := [1..Length(m)];
54+
cols := [1..Length(m[1])];
55+
for u in [1..QuoInt(100000,Length(m)*Length(m[1]))] do
56+
for i in rows do
57+
for j in cols do
58+
x:=f(m,i,j);
59+
od;
60+
od;
61+
od;
62+
end);
63+
64+
end;
65+
66+
TestWritingMatrix := function(m)
67+
local f;
68+
69+
PrintHeadline("m[i][j]:=elm");
70+
MyBench(function()
71+
local u, i, j, rows, cols, x;
72+
x:=m[1][1];
73+
rows := [1..Length(m)];
74+
cols := [1..Length(m[1])];
75+
for u in [1..QuoInt(100000,Length(m)*Length(m[1]))] do
76+
for i in rows do
77+
for j in cols do
78+
m[i][j]:=x;
79+
od;
80+
od;
81+
od;
82+
end);
83+
84+
PrintHeadline("m[i,j]:=elm");
85+
MyBench(function()
86+
local u, i, j, rows, cols, x;
87+
x:=m[1][1];
88+
rows := [1..Length(m)];
89+
cols := [1..Length(m[1])];
90+
for u in [1..QuoInt(100000,Length(m)*Length(m[1]))] do
91+
for i in rows do
92+
for j in cols do
93+
m[i,j]:=x;
94+
od;
95+
od;
96+
od;
97+
end);
98+
99+
PrintHeadline("SetMatElm(m,i,j,elm)");
100+
MyBench(function()
101+
local u, i, j, rows, cols, x;
102+
x:=m[1][1];
103+
rows := [1..Length(m)];
104+
cols := [1..Length(m[1])];
105+
for u in [1..QuoInt(100000,Length(m)*Length(m[1]))] do
106+
for i in rows do
107+
for j in cols do
108+
SetMatElm(m,i,j,x);
109+
od;
110+
od;
111+
od;
112+
end);
113+
114+
PrintHeadline("SetMatElm(m,i,j,elm) with prefetched method");
115+
f:=ApplicableMethod(SetMatElm, [m,1,1,m[1][1]]);;
116+
MyBench(function()
117+
local u, i, j, rows, cols, x;
118+
x:=m[1][1];
119+
rows := [1..Length(m)];
120+
cols := [1..Length(m[1])];
121+
for u in [1..QuoInt(100000,Length(m)*Length(m[1]))] do
122+
for i in rows do
123+
for j in cols do
124+
f(m,i,j,x);
125+
od;
126+
od;
127+
od;
128+
end);
129+
end;
130+
131+
RunMatTest := function(desc, m)
132+
Print("\n");
133+
PrintBoxed(Concatenation("Testing ", desc));
134+
TestReadingMatrix(m);
135+
Print(TextAttr.2, "...now testing write access...\n", TextAttr.reset);
136+
TestWritingMatrix(m);
137+
end;
138+
139+
m:=IdentityMat(10);;
140+
RunMatTest("integer matrix", m);
141+
142+
m:=IdentityMat(10,GF(2));;
143+
RunMatTest("GF(2) rowlist", m);
144+
145+
m:=IdentityMat(10,GF(2));; ConvertToMatrixRep(m);;
146+
RunMatTest("GF(2) compressed matrix", m);
147+
148+
m:=IdentityMat(10,GF(7));;
149+
RunMatTest("GF(7) rowlist", m);
150+
151+
m:=IdentityMat(10,GF(7));; ConvertToMatrixRep(m);;
152+
RunMatTest("GF(7) compressed matrix", m);
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
ReadGapRoot("benchmark/matobj/bench.g");
2+
3+
4+
TestCreatingVector := function(v)
5+
Error("TODO");
6+
end;
7+
8+
# TODO:
9+
TestCreatingMatrix := function(filter, ring)
10+
local example_mat;
11+
12+
example_mat := NewZeroMatrix(filter, ring, 1, 1);
13+
14+
PrintHeadline("NewZeroMatrix");
15+
MyBench(function()
16+
local m, n, mat;
17+
for m in [1..10] do
18+
for n in [1..10] do
19+
mat := NewZeroMatrix(filter, ring, m, n);
20+
od;
21+
od;
22+
end);
23+
24+
PrintHeadline("ZeroMatrix( filt, R, m, n )");
25+
MyBench(function()
26+
local m, n, mat;
27+
for m in [1..10] do
28+
for n in [1..10] do
29+
mat := ZeroMatrix(filter, ring, m, n);
30+
od;
31+
od;
32+
end);
33+
34+
PrintHeadline("ZeroMatrix( m, n, M )");
35+
MyBench(function()
36+
local m, n, mat;
37+
for m in [1..10] do
38+
for n in [1..10] do
39+
mat := ZeroMatrix(m, n, example_mat);
40+
od;
41+
od;
42+
end);
43+
44+
PrintHeadline("NewIdentityMatrix");
45+
MyBench(function()
46+
local n, mat;
47+
for n in [1..100] do
48+
mat := NewIdentityMatrix(filter, ring, n);
49+
od;
50+
end);
51+
52+
PrintHeadline("IdentityMatrix( filt, R, n )");
53+
MyBench(function()
54+
local n, mat;
55+
for n in [1..100] do
56+
mat := IdentityMatrix(filter, ring, n);
57+
od;
58+
end);
59+
60+
PrintHeadline("IdentityMatrix( n, M )");
61+
MyBench(function()
62+
local n, mat;
63+
for n in [1..100] do
64+
mat := IdentityMatrix(n, example_mat);
65+
od;
66+
end);
67+
68+
# TODO: ZeroMatrix with various arguments
69+
# TODO: NewIdentityMatrix
70+
# TODO: IdentityMatrix
71+
# TODO: NewMatrix
72+
# TODO: Matrix
73+
end;
74+
75+
RunMatTest := function(desc, filter, ring)
76+
Print("\n");
77+
PrintBoxed(Concatenation("Testing ", desc));
78+
TestCreatingMatrix(filter, ring);
79+
Print(TextAttr.2, "...now testing write access...\n", TextAttr.reset);
80+
end;
81+
82+
RunMatTest("GF(2) IsPlistMatrixRep", IsPlistMatrixRep, GF(2));
83+
RunMatTest("integer IsPlistMatrixRep", IsPlistMatrixRep, Integers);
84+
RunMatTest("rational IsPlistMatrixRep", IsPlistMatrixRep, Rationals);
85+
86+
# TODO: other reps
87+
# TODO: other compare with creating plist-of-plist

0 commit comments

Comments
 (0)