1
+ % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
+ %% Main function. All the tests are run here. %%
3
+ %% The functions declarations can be found at the end. %%
4
+ % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5
+
1
6
function perf()
2
7
3
- warning off ;
4
- if exist(' OCTAVE_VERSION' ) == 0
5
- maxNumCompThreads(1 );
6
- end
8
+ warning off ;
9
+ if exist(' OCTAVE_VERSION' ) == 0
10
+ maxNumCompThreads(1 );
11
+ end
12
+
13
+ f = fib(20 );
14
+ assert(f == 6765 )
15
+ timeit(' fib' , @fib , 20 )
16
+
17
+ timeit(' parse_int' , @parseintperf , 1000 )
18
+
19
+ %% array constructors %%
20
+
21
+ % o = ones(200,200);
22
+ % assert(all(o) == 1)
23
+ % timeit('ones', @ones, 200, 200)
24
+
25
+ % assert(all(matmul(o) == 200))
26
+ % timeit('AtA', @matmul, o)
27
+
28
+ mandel(complex(-.53 ,.68 ));
29
+ assert(sum(sum(mandelperf(true ))) == 14791 )
30
+ timeit(' mandel' , @mandelperf , true )
31
+
32
+ assert(issorted(sortperf(5000 )))
33
+ timeit(' quicksort' , @sortperf , 5000 )
34
+
35
+ s = pisum(true );
36
+ assert(abs(s - 1.644834071848065 ) < 1e- 12 );
37
+ timeit(' pi_sum' ,@pisum , true )
38
+
39
+ % s = pisumvec(true);
40
+ % assert(abs(s-1.644834071848065) < 1e-12);
41
+ % timeit('pi_sum_vec',@pisumvec, true)
42
+
43
+ [s1 , s2 ] = randmatstat(1000 );
44
+ assert(round(10 * s1 ) > 5 && round(10 * s1 ) < 10 );
45
+ timeit(' rand_mat_stat' , @randmatstat , 1000 )
46
+
47
+ timeit(' rand_mat_mul' , @randmatmul , 1000 );
48
+
49
+ printfd(1 )
50
+ timeit(' printfd' , @printfd , 100000 )
51
+
52
+ end
53
+
54
+
55
+ % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56
+ %% Functions declarations %%
57
+ % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7
58
8
59
function assert(bool )
9
60
if ~bool
@@ -39,10 +90,6 @@ function timeit(name, func, varargin)
39
90
end
40
91
end
41
92
42
- f = fib(20 );
43
- assert(f == 6765 )
44
- timeit(' fib' , @fib , 20 )
45
-
46
93
%% parse int %%
47
94
48
95
function n = parseintperf(t )
@@ -53,21 +100,12 @@ function timeit(name, func, varargin)
53
100
assert(m == n );
54
101
end
55
102
end
56
- timeit(' parse_int' , @parseintperf , 1000 )
57
-
58
- %% array constructors %%
59
-
60
- % o = ones(200,200);
61
- % assert(all(o) == 1)
62
- % timeit('ones', @ones, 200, 200)
63
103
64
104
%% matmul and transpose %%
65
105
66
106
% function oo = matmul(o)
67
107
% oo = o * o.';
68
108
% end
69
- % assert(all(matmul(o) == 200))
70
- % timeit('AtA', @matmul, o)
71
109
72
110
%% mandelbrot set: complex arithmetic and comprehensions %%
73
111
@@ -83,8 +121,6 @@ function timeit(name, func, varargin)
83
121
n = 80 ;
84
122
end
85
123
86
- mandel(complex(-.53 ,.68 ));
87
-
88
124
function M = mandelperf(ignore )
89
125
M = zeros(length(-2.0 : .1 : 0.5 ), length(-1 : .1 : 1 ));
90
126
count = 1 ;
@@ -95,8 +131,6 @@ function timeit(name, func, varargin)
95
131
end
96
132
end
97
133
end
98
- assert(sum(sum(mandelperf(true ))) == 14791 )
99
- timeit(' mandel' , @mandelperf , true )
100
134
101
135
%% numeric vector quicksort %%
102
136
@@ -130,8 +164,6 @@ function timeit(name, func, varargin)
130
164
v = rand(n ,1 );
131
165
v = qsort(v );
132
166
end
133
- assert(issorted(sortperf(5000 )))
134
- timeit(' quicksort' , @sortperf , 5000 )
135
167
136
168
%% slow pi series %%
137
169
@@ -145,10 +177,6 @@ function timeit(name, func, varargin)
145
177
end
146
178
end
147
179
148
- s = pisum(true );
149
- assert(abs(s - 1.644834071848065 ) < 1e- 12 );
150
- timeit(' pi_sum' ,@pisum , true )
151
-
152
180
%% slow pi series, vectorized %%
153
181
154
182
function s = pisumvec(ignore )
@@ -158,10 +186,6 @@ function timeit(name, func, varargin)
158
186
end
159
187
end
160
188
161
- % s = pisumvec(true);
162
- % assert(abs(s-1.644834071848065) < 1e-12);
163
- % timeit('pi_sum_vec',@pisumvec, true)
164
-
165
189
%% random matrix statistics %%
166
190
167
191
function [s1 , s2 ] = randmatstat(t )
@@ -182,10 +206,6 @@ function timeit(name, func, varargin)
182
206
s2 = std(w )/mean(w );
183
207
end
184
208
185
- [s1 , s2 ] = randmatstat(1000 );
186
- assert(round(10 * s1 ) > 5 && round(10 * s1 ) < 10 );
187
- timeit(' rand_mat_stat' , @randmatstat , 1000 )
188
-
189
209
function t = mytranspose(x )
190
210
[m , n ] = size(x );
191
211
t = zeros(n , m );
@@ -202,8 +222,6 @@ function timeit(name, func, varargin)
202
222
X = rand(n ,n )*rand(n ,n );
203
223
end
204
224
205
- timeit(' rand_mat_mul' , @randmatmul , 1000 );
206
-
207
225
%% printf %%
208
226
209
227
function printfd(n )
@@ -213,8 +231,3 @@ function printfd(n)
213
231
end
214
232
fclose(f );
215
233
end
216
-
217
- printfd(1 )
218
- timeit(' printfd' , @printfd , 100000 )
219
-
220
- end
0 commit comments