-
Notifications
You must be signed in to change notification settings - Fork 5
/
relspeed_Q32_Q64.jl
175 lines (129 loc) · 4.64 KB
/
relspeed_Q32_Q64.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
using FastRationals
using Polynomials, LinearAlgebra, BenchmarkTools, MacroTools
BenchmarkTools.DEFAULT_PARAMETERS.evals = 1;
BenchmarkTools.DEFAULT_PARAMETERS.samples = 200;
BenchmarkTools.DEFAULT_PARAMETERS.time_tolerance = 1.0e-8;
BenchmarkTools.DEFAULT_PARAMETERS.overhead = BenchmarkTools.estimate_overhead();
walk(x, inner, outer) = outer(x)
walk(x::Expr, inner, outer) = outer(Expr(x.head, map(inner, x.args)...))
postwalk(f, x) = walk(x, x -> postwalk(f, x), f)
function referred(expr::Expr)
if expr.head == :$
:($(Expr(:$, :(Ref($(expr.args...)))))[])
else
expr
end
end
referred(x) = x
"""
@noelide _bmacro_ expression
where _bmacro_ is one of @btime, @belapsed, @benchmark
Wraps all interpolated code in _expression_ in a __Ref()__ to
stop the compiler from cheating at simple benchmarks. Works
with any macro that accepts interpolation
#Example
julia> @btime \$a + \$b
0.024 ns (0 allocations: 0 bytes)
3
julia> @noelide @btime \$a + \$b
1.277 ns (0 allocations: 0 bytes)
3
"""
macro noelide(expr)
out = postwalk(referred, expr) |> esc
end
function testadd(x,y,z)
a = x + y
b = a + z
c = b + a
d = c + x
return d
end
function testmul(x,y,z)
a = x * y
b = a * z
c = z * x
d = a * b
return d
end
function testarith(x,y,z)
a = x + y
b = x * y
c = z - b
d = a / c
return d
end
w32,x32,y32,z32 = Rational{Int32}.([1//12, -2//77, 3//54, -4//17]); q32 = Int32(1)//Int32(7);
u32,v32 = w32+z32, w32-z32
w64,x64,y64,z64 = Rational{Int64}.([1//12, -2//77, 3//54, -4//17]); q64 = Int64(1)//Int64(7);
u64,v64 = w64+z64, w64-z64
ply32 = Poly([w32, x32, y32, z32]);
ply64 = Poly([w64, x64, y64, z64]);
ply64w = Poly([u64, v64, w64, x64, y64, z64]);
a32,b32,c32,d32,e32,f32 = FastQ32.((w32,x32,y32,z32,u32,v32)); fastq32 = FastQ32(q32);
fastply32=Poly([a32,b32,c32,d32]);
a64,b64,c64,d64,e64,f64 = FastQ64.((w64,x64,y64,z64,u64,v64)); fastq64 = FastQ64(q64);
fastply64=Poly([a64,b64,c64,d64]);
fastply64w=Poly([a64,b64,c64,d64,e64,f64]);
m = [1//1 1//5 1//9 1//13; 1//2 1//6 1//10 1//14; 1//3 1//7 1//11 1//15; 1//4 1//8 1//12 1//16];
m32 = Rational{Int32}.(m);
m64 = Rational{Int64}.(m);
mfast32 = FastQ32.(m);
mfast64 = FastQ64.(m);
relspeed_arith32 =
round( (@noelide @belapsed testarith($x32,$y32,$z32)) /
(@noelide @belapsed testarith($a32,$b32,$c32)), digits=1);
relspeed_arith64 =
round( (@noelide @belapsed testarith($x64,$y64,$z64)) /
(@noelide @belapsed testarith($a64,$b64,$c64)), digits=1);
relspeed_add32 =
round( (@noelide @belapsed testadd($x32,$y32,$z32)) /
(@noelide @belapsed testadd($a32,$b32,$c32)), digits=1);
relspeed_add64 =
round( (@noelide @belapsed testadd($x64,$y64,$z64)) /
(@noelide @belapsed testadd($a64,$b64,$c64)), digits=1);
relspeed_mul32 =
round( (@noelide @belapsed testmul($x32,$y32,$z32)) /
(@noelide @belapsed testmul($a32,$b32,$c32)), digits=1);
relspeed_mul64 =
round( (@noelide @belapsed testmul($x64,$y64,$z64)) /
(@noelide @belapsed testmul($a64,$b64,$c64)), digits=1);
relspeed_ply32 =
round( (@noelide @belapsed polyval($ply32, $q32)) /
(@noelide @belapsed polyval($fastply32, $fastq32)), digits=1);
relspeed_ply64 =
round( (@noelide @belapsed polyval($ply64, $q64)) /
(@noelide @belapsed polyval($fastply64, $fastq64)), digits=1);
relspeed_ply64w =
round( (@noelide @belapsed polyval($ply64w, $q64)) /
(@noelide @belapsed polyval($fastply64w, $fastq64)), digits=1);
relspeed_matmul32 =
round( (@noelide @belapsed $m32*$m32) /
(@noelide @belapsed $mfast32*$mfast32), digits=1);
relspeed_matmul64 =
round( (@noelide @belapsed $m64*$m64) /
(@noelide @belapsed $mfast64*$mfast64), digits=1);
relspeed_matlu32 =
round( (@noelide @belapsed lu($m32)) /
(@noelide @belapsed lu($mfast32)), digits=1);
relspeed_matlu64 =
round( (@noelide @belapsed lu($m64)) /
(@noelide @belapsed lu($mfast64)), digits=1);
relspeed_matinv32 =
round( (@noelide @belapsed inv($m32)) /
(@noelide @belapsed inv($mfast32)), digits=1);
relspeed_matinv64 =
round( (@noelide @belapsed inv($m64)) /
(@noelide @belapsed inv($mfast64)), digits=1);
relspeeds = string(
"\n\n\trelative speeds",
"\n\t (32)\t (64)\n\n",
"mul: \t $relspeed_mul32 \t $relspeed_mul64 \n",
"muladd:\t $relspeed_arith32 \t $relspeed_arith64 \n",
"add: \t $relspeed_add32 \t $relspeed_add64 \n",
"poly: \t $relspeed_ply32 \t $relspeed_ply64w \n",
"matmul:\t $relspeed_matmul32 \t $relspeed_matmul64\n",
"matlu: \t $relspeed_matlu32 \t $relspeed_matlu64 \n",
"matinv:\t $relspeed_matinv32 \t $relspeed_matinv64 \n");
print(relspeeds);
;