1 /*
2 * Copyright (c) 2007 - 2015 Joseph Gaeddert
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23 #include <sys/resource.h>
24 #include "liquid.h"
25
26 // Helper function to keep code base small
matrixf_inv_bench(struct rusage * _start,struct rusage * _finish,unsigned long int * _num_iterations,unsigned int _n)27 void matrixf_inv_bench(struct rusage *_start,
28 struct rusage *_finish,
29 unsigned long int *_num_iterations,
30 unsigned int _n)
31 {
32 // normalize number of iterations
33 // time ~ _n ^ 2
34 *_num_iterations /= _n * _n;
35 if (*_num_iterations < 1) *_num_iterations = 1;
36
37 float x[_n*_n];
38 unsigned int i;
39 for (i=0; i<_n*_n; i++)
40 x[i] = randnf();
41
42 // start trials
43 getrusage(RUSAGE_SELF, _start);
44 for (i=0; i<(*_num_iterations); i++) {
45 matrixf_inv(x,_n,_n);
46 matrixf_inv(x,_n,_n);
47 matrixf_inv(x,_n,_n);
48 matrixf_inv(x,_n,_n);
49 }
50 getrusage(RUSAGE_SELF, _finish);
51 *_num_iterations *= 4;
52 }
53
54 #define MATRIXF_INV_BENCHMARK_API(N) \
55 ( struct rusage *_start, \
56 struct rusage *_finish, \
57 unsigned long int *_num_iterations) \
58 { matrixf_inv_bench(_start, _finish, _num_iterations, N); }
59
60 void benchmark_matrixf_inv_n2 MATRIXF_INV_BENCHMARK_API(2)
61 void benchmark_matrixf_inv_n4 MATRIXF_INV_BENCHMARK_API(4)
62 void benchmark_matrixf_inv_n8 MATRIXF_INV_BENCHMARK_API(8)
63 void benchmark_matrixf_inv_n16 MATRIXF_INV_BENCHMARK_API(16)
64 void benchmark_matrixf_inv_n32 MATRIXF_INV_BENCHMARK_API(32)
65 void benchmark_matrixf_inv_n64 MATRIXF_INV_BENCHMARK_API(64)
66
67