/
bench.mgm
126 lines (100 loc) · 2.72 KB
/
bench.mgm
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
120
121
122
123
124
125
/*
All the test routines take three parameters:
p : size of the base field
l : degree of the tower
h : height of the tower
and return a list of lists containing timings for various
operations (create, embed, push, lift) at each level.
They also print some summary of timings for convenience.
*/
// subroutine used to test lift/push
function test_lp(K, l, trials)
tpush := [];
tlift := [];
for i := 2 to #K do
tl := 0; tp := 0;
for j := 1 to trials do
a := Random(K[i]);
t := Cputime();
_ := Eltseq(a, K[i-1]);
tp +:= Cputime(t);
B := [Random(K[i-1]) : k in [1..l]];
t := Cputime();
_ := Seqelt(B, K[i]);
tl +:= Cputime(t);
end for;
tpush[i-1] := tp/trials;
tlift[i-1] := tl/trials;
end for;
print "Push time:", &+tpush;
print "Lift time:", &+tlift;
return tpush, tlift;
end function;
// Construct tower using default ext<> constructor
function default_ext(p, l, h)
K := [GF(p)];
tcreat := [];
for i := 2 to h+1 do
t := Cputime();
K[i] := ext<K[i-1]|l>;
tcreat[i-1] := Cputime(t);
end for;
print "Creation time:", &+tcreat;
tpush, tlift := test_lp(K, l, 3);
return tcreat, tpush, tlift;
end function;
// Construct tower using default sub<> constructor
function default_sub(p, l, h)
K := [GF(p)];
tcreat := [];
t := Cputime();
K[h+1] := GF(p, l^h);
tcreat[h] := Cputime(t);
for i := h to 2 by -1 do
t := Cputime();
K[i] := sub<K[i+1]|l^(i-1)>;
tcreat[i-1] := Cputime(t);
end for;
print "Creation time:", &+tcreat;
tpush, tlift := test_lp(K, l, 3);
return tcreat, tpush, tlift;
end function;
// Construct tower creating the default fields first, then embedding
function default_embed(p, l, h)
K := [];
K[1] := GF(p);
tcreat := [];
tembed := [];
for i := 2 to h+1 do
t := Cputime();
K[i] := GF(p, l^(i-1));
tcreat[i-1] := Cputime(t);
t := Cputime();
Embed(K[i-1], K[i]);
tembed[i-1] := Cputime(t);
end for;
print "Creation time:", &+tcreat;
print "Embedding time:", &+tembed;
tpush, tlift := test_lp(K, l, 3);
return tcreat, tembed, tpush, tlift;
end function;
// Construct tower creating fields from random polynomials, then embedding
function random_embed(p, l, h)
K := [];
K[1] := GF(p);
tcreat := [];
tembed := [];
for i := 2 to h+1 do
P := RandomIrreduciblePolynomial(K[1], l^(i-1));
t := Cputime();
K[i] := ext<K[1]|P>;
tcreat[i-1] := Cputime(t);
t := Cputime();
Embed(K[i-1], K[i]);
tembed[i-1] := Cputime(t);
end for;
print "Creation time:", &+tcreat;
print "Embedding time:", &+tembed;
tpush, tlift := test_lp(K, l, 3);
return tcreat, tembed, tpush, tlift;
end function;