File: faustbench.cpp

package info (click to toggle)
faust 2.14.4~repack2-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 276,136 kB
  • sloc: cpp: 231,578; ansic: 15,403; sh: 10,871; java: 6,917; objc: 4,085; makefile: 3,002; cs: 1,077; ruby: 951; python: 885; xml: 550; yacc: 516; lex: 233; lisp: 201
file content (262 lines) | stat: -rw-r--r-- 10,165 bytes parent folder | download
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/************************************************************************
    FAUST Architecture File
    Copyright (C) 2017 GRAME, Centre National de Creation Musicale
    ---------------------------------------------------------------------
    This Architecture section is free software; you can redistribute it 
    and/or modify it under the terms of the GNU General Public License 
    as published by the Free Software Foundation; either version 3 of 
    the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License 
    along with this program; If not, see <http://www.gnu.org/licenses/>.

    EXCEPTION : As a special exception, you may create a larger work 
    that contains this FAUST architecture section and distribute  
    that work under terms of your choice, so long as this FAUST 
    architecture section is not modified. 

 ************************************************************************/

#include <vector>
#include <iostream>
#include <string>
#include <math.h>

#include "faust/gui/UI.h"
#include "faust/dsp/dsp.h"
#include "faust/dsp/dsp-bench.h"
#include "faust/misc.h"

#if defined(ALL_TESTS)

#include "dsp_scal.h"
#include "dsp_scal_exp10.h"

#include "dsp_vec0_4.h"
#include "dsp_vec0_8.h"
#include "dsp_vec0_16.h"
#include "dsp_vec0_32.h"
#include "dsp_vec0_64.h"
#include "dsp_vec0_128.h"
#include "dsp_vec0_256.h"
#include "dsp_vec0_512.h"

#include "dsp_vec1_4.h"
#include "dsp_vec1_8.h"
#include "dsp_vec1_16.h"
#include "dsp_vec1_32.h"
#include "dsp_vec1_64.h"
#include "dsp_vec1_128.h"
#include "dsp_vec1_256.h"
#include "dsp_vec1_512.h"

#include "dsp_vec0g_4.h"
#include "dsp_vec0g_8.h"
#include "dsp_vec0g_16.h"
#include "dsp_vec0g_32.h"
#include "dsp_vec0g_64.h"
#include "dsp_vec0g_128.h"
#include "dsp_vec0g_256.h"
#include "dsp_vec0g_512.h"

#include "dsp_vec1g_4.h"
#include "dsp_vec1g_8.h"
#include "dsp_vec1g_16.h"
#include "dsp_vec1g_32.h"
#include "dsp_vec1g_64.h"
#include "dsp_vec1g_128.h"
#include "dsp_vec1g_256.h"
#include "dsp_vec1g_512.h"

#elif defined(FAST_TESTS)

#include "dsp_scal.h"
#include "dsp_vec0_32.h"
#include "dsp_vec1_32.h"
#include "dsp_vec0g_32.h"
#include "dsp_vec1g_32.h"

#elif defined(SINGLE_TESTS)

#include "dsp_scal.h"

#endif

using namespace std;

#define ADD_DOUBLE string((sizeof(FAUSTFLOAT) == 8) ? "-double " : "")

ofstream* gFaustbenchLog = nullptr;

static double bench(dsp* dsp, const string& name, int run, bool trace)
{
    measure_dsp mes(dsp, 512, 5., trace);  // Buffer_size and duration in sec of  measure
    for (int i = 0; i < run; i++) {
        mes.measure();
        if (trace) cout << name << " : " << mes.getStats() << " " << "(DSP CPU % : " << (mes.getCPULoad() * 100) << ")" << endl;
        FAUSTBENCH_LOG<double>(mes.getStats());
    }
    return mes.getStats();
}

extern "C" int bench_all(const char* name, int run, bool trace)
{
    vector<double> measures;
    vector<string> options;
    
    if (trace) cout << "DSP bench of " << name << " compiled in C++ running with FAUSTFLOAT = " << ((sizeof(FAUSTFLOAT) == 4) ? "float" : "double") << endl;
    
#if defined(ALL_TESTS)
    
    options.push_back(ADD_DOUBLE + "-scal");
    options.push_back(ADD_DOUBLE + "-scal -exp10");
    
    options.push_back(ADD_DOUBLE + "-vec -lv 0 -vs 4");
    options.push_back(ADD_DOUBLE + "-vec -lv 0 -vs 8");
    options.push_back(ADD_DOUBLE + "-vec -lv 0 -vs 16");
    options.push_back(ADD_DOUBLE + "-vec -lv 0 -vs 32");
    options.push_back(ADD_DOUBLE + "-vec -lv 0 -vs 64");
    options.push_back(ADD_DOUBLE + "-vec -lv 0 -vs 128");
    options.push_back(ADD_DOUBLE + "-vec -lv 0 -vs 256");
    options.push_back(ADD_DOUBLE + "-vec -lv 0 -vs 512");
    
    options.push_back(ADD_DOUBLE + "-vec -lv 0 -vs 4 -g");
    options.push_back(ADD_DOUBLE + "-vec -lv 0 -vs 8 -g");
    options.push_back(ADD_DOUBLE + "-vec -lv 0 -vs 16 -g");
    options.push_back(ADD_DOUBLE + "-vec -lv 0 -vs 32 -g");
    options.push_back(ADD_DOUBLE + "-vec -lv 0 -vs 64 -g");
    options.push_back(ADD_DOUBLE + "-vec -lv 0 -vs 128 -g");
    options.push_back(ADD_DOUBLE + "-vec -lv 0 -vs 256 -g");
    options.push_back(ADD_DOUBLE + "-vec -lv 0 -vs 512 -g");
    
    options.push_back(ADD_DOUBLE + "-vec -lv 1 -vs 4");
    options.push_back(ADD_DOUBLE + "-vec -lv 1 -vs 8");
    options.push_back(ADD_DOUBLE + "-vec -lv 1 -vs 16");
    options.push_back(ADD_DOUBLE + "-vec -lv 1 -vs 32");
    options.push_back(ADD_DOUBLE + "-vec -lv 1 -vs 64");
    options.push_back(ADD_DOUBLE + "-vec -lv 1 -vs 128");
    options.push_back(ADD_DOUBLE + "-vec -lv 1 -vs 256");
    options.push_back(ADD_DOUBLE + "-vec -lv 1 -vs 512");
    
    options.push_back(ADD_DOUBLE + "-vec -lv 1 -vs 4 -g");
    options.push_back(ADD_DOUBLE + "-vec -lv 1 -vs 8 -g");
    options.push_back(ADD_DOUBLE + "-vec -lv 1 -vs 16 -g");
    options.push_back(ADD_DOUBLE + "-vec -lv 1 -vs 32 -g");
    options.push_back(ADD_DOUBLE + "-vec -lv 1 -vs 64 -g");
    options.push_back(ADD_DOUBLE + "-vec -lv 1 -vs 128 -g");
    options.push_back(ADD_DOUBLE + "-vec -lv 1 -vs 256 -g");
    options.push_back(ADD_DOUBLE + "-vec -lv 1 -vs 512 -g");
    
#elif defined(FAST_TESTS)
    
    options.push_back(ADD_DOUBLE + "-scal");
    options.push_back(ADD_DOUBLE + "-scal -exp10");
    options.push_back(ADD_DOUBLE + "-vec -lv 0 -vs 32");
    options.push_back(ADD_DOUBLE + "-vec -lv 0 -vs 32 -g");
    options.push_back(ADD_DOUBLE + "-vec -lv 1 -vs 32");
    options.push_back(ADD_DOUBLE + "-vec -lv 1 -vs 32 -g");
    
#elif defined(SINGLE_TESTS)
    
    options.push_back(ADD_DOUBLE + "-scal");
    
#endif
    
    int ind = 0;
    
#if defined(ALL_TESTS)
    
    // Scalar
    measures.push_back(bench(new dsp_scal(), options[ind++], run, trace));
    measures.push_back(bench(new dsp_scal_exp10(), options[ind++], run, trace));
    
    // Vector -lv 0
    measures.push_back(bench(new dsp_vec1_4(), options[ind++], run, trace));
    measures.push_back(bench(new dsp_vec0_8(), options[ind++], run, trace));
    measures.push_back(bench(new dsp_vec0_16(), options[ind++], run, trace));
    measures.push_back(bench(new dsp_vec0_32(), options[ind++], run, trace));
    measures.push_back(bench(new dsp_vec0_64(), options[ind++], run, trace));
    measures.push_back(bench(new dsp_vec0_128(), options[ind++], run, trace));
    measures.push_back(bench(new dsp_vec0_256(), options[ind++], run, trace));
    measures.push_back(bench(new dsp_vec0_512(), options[ind++], run, trace));
    
    measures.push_back(bench(new dsp_vec1_4(), options[ind++], run, trace));
    measures.push_back(bench(new dsp_vec0g_8(), options[ind++], run, trace));
    measures.push_back(bench(new dsp_vec0g_16(), options[ind++], run, trace));
    measures.push_back(bench(new dsp_vec0g_32(), options[ind++], run, trace));
    measures.push_back(bench(new dsp_vec0g_64(), options[ind++], run, trace));
    measures.push_back(bench(new dsp_vec0g_128(), options[ind++], run, trace));
    measures.push_back(bench(new dsp_vec0g_256(), options[ind++], run, trace));
    measures.push_back(bench(new dsp_vec0g_512(), options[ind++], run, trace));
    
    // Vector -lv 1
    measures.push_back(bench(new dsp_vec1_4(), options[ind++], run, trace));
    measures.push_back(bench(new dsp_vec1_8(), options[ind++], run, trace));
    measures.push_back(bench(new dsp_vec1_16(), options[ind++], run, trace));
    measures.push_back(bench(new dsp_vec1_32(), options[ind++], run, trace));
    measures.push_back(bench(new dsp_vec1_64(), options[ind++], run, trace));
    measures.push_back(bench(new dsp_vec1_128(), options[ind++], run, trace));
    measures.push_back(bench(new dsp_vec1_256(), options[ind++], run, trace));
    measures.push_back(bench(new dsp_vec1_512(), options[ind++], run, trace));
    
    measures.push_back(bench(new dsp_vec1g_4(), options[ind++], run, trace));
    measures.push_back(bench(new dsp_vec1g_8(), options[ind++], run, trace));
    measures.push_back(bench(new dsp_vec1g_16(), options[ind++], run, trace));
    measures.push_back(bench(new dsp_vec1g_32(), options[ind++], run, trace));
    measures.push_back(bench(new dsp_vec1g_64(), options[ind++], run, trace));
    measures.push_back(bench(new dsp_vec1g_128(), options[ind++], run, trace));
    measures.push_back(bench(new dsp_vec1g_256(), options[ind++], run, trace));
    measures.push_back(bench(new dsp_vec1g_512(), options[ind++], run, trace));
    
#elif defined(FAST_TESTS)
    
    measures.push_back(bench(new dsp_scal(), options[ind++], run, trace));
    measures.push_back(bench(new dsp_scal_exp10(), options[ind++], run, trace));
    
    measures.push_back(bench(new dsp_vec0_32(), options[ind++], run, trace));
    measures.push_back(bench(new dsp_vec0g_32(), options[ind++], run, trace));
    measures.push_back(bench(new dsp_vec1_32(), options[ind++], run, trace));
    measures.push_back(bench(new dsp_vec1g_32(), options[ind++], run, trace));
    
#elif defined(SINGLE_TESTS)
    
    measures.push_back(bench(new dsp_scal(), options[ind++], run, trace));
    
#endif
    
    vector<double> measures1 = measures;
    sort(measures1.begin(), measures1.end());
    
    vector <double>::iterator it = find(measures.begin(), measures.end(), measures1[measures1.size()-1]);
    long int pos = distance(measures.begin(), it);
    
    if (trace) {
        cout << "Best value is : " << measures1[measures1.size()-1] << " with " << options[pos] << endl;
    } else {
        cout << options[pos] << endl;
    }
  	return 1;
}

#ifndef TARGET_OS_IPHONE

int main(int argc, char* argv[])
{
    if (isopt(argv, "-h") || isopt(argv, "-help")) {
        cout << "faustbench [-notrace] [-run <num>] foo.dsp" << endl;
        return 0;
    }
    
    //FAUSTBENCH_LOG<string>("faustbench C++");
    
    int run = lopt(argv, "-run", 1);
    bool is_trace = !isopt(argv, "-notrace");
    return bench_all(argv[0], run, is_trace);
}

#endif