-
Notifications
You must be signed in to change notification settings - Fork 62
/
gnuradio_benchmark.py
520 lines (412 loc) · 17.3 KB
/
gnuradio_benchmark.py
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
import os
import sys
import time
import json
import math
import array
import tempfile
import random
import collections
from gnuradio import gr
from gnuradio import audio, analog, digital, filter, blocks
################################################################################
# Benchmark parameters
# Duration of each benchmark trial
BENCH_TRIAL_DURATION = 5.0
# Number of benchmark trials to average
BENCH_NUM_TRIALS = 5
# Benchmark Suite
BenchmarkSuite = []
################################################################################
# Decorator for defining benchmarks in the suite
def benchmark(test_name, block_name):
def wrapped(f):
BenchmarkSuite.append((test_name, block_name, f))
return f
return wrapped
################################################################################
@benchmark("Five Back to Back FIR Filters (FFT, 256 Real taps, Complex input)", "filter.fft_filter_ccf")
def test_five_fft_filter():
top = gr.top_block()
src = blocks.null_source(gr.sizeof_gr_complex)
filters = [filter.fft_filter_ccf(1, [random.random() for j in range(256)]) for i in range(5)]
probe = blocks.probe_rate(gr.sizeof_gr_complex)
top.connect(*([src] + filters + [probe]))
return top, probe
@benchmark("Zero Source (Complex)", "blocks.null_source")
def test_null_source_complex():
top = gr.top_block()
src = blocks.null_source(gr.sizeof_gr_complex)
probe = blocks.probe_rate(gr.sizeof_gr_complex)
top.connect(src, probe)
return top, probe
@benchmark("Zero Source (Real)", "blocks.null_source")
def test_null_source_real():
top = gr.top_block()
src = blocks.null_source(gr.sizeof_float)
probe = blocks.probe_rate(gr.sizeof_float)
top.connect(src, probe)
return top, probe
@benchmark("Raw File Source (float)", "blocks.file_descriptor_source")
def test_file_descriptor_source():
tmp_f = tempfile.TemporaryFile()
array.array('f', [random.random() for _ in range(262144)]).tofile(tmp_f)
tmp_f.seek(0)
top = gr.top_block()
src = blocks.file_descriptor_source(gr.sizeof_float, os.dup(tmp_f.fileno()), True)
probe = blocks.probe_rate(gr.sizeof_float)
top.connect(src, probe)
return top, probe
@benchmark("Uniform Random Source (Complex)", "analog.fastnoise_source_c")
def test_noise_source_complex():
top = gr.top_block()
src = analog.fastnoise_source_c(analog.GR_UNIFORM, math.sqrt(2))
probe = blocks.probe_rate(gr.sizeof_gr_complex)
top.connect(src, probe)
return top, probe
@benchmark("Uniform Random Source (Real)", "analog.fastnoise_source_f")
def test_noise_source_real():
top = gr.top_block()
src = analog.fastnoise_source_f(analog.GR_UNIFORM, math.sqrt(2))
probe = blocks.probe_rate(gr.sizeof_float)
top.connect(src, probe)
return top, probe
@benchmark("Signal Source (Complex Exponential)", "analog.sig_source_c")
def test_sig_source_complex_exponential():
top = gr.top_block()
src = analog.sig_source_c(1e6, analog.GR_COS_WAVE, 200e3, 1.0)
probe = blocks.probe_rate(gr.sizeof_gr_complex)
top.connect(src, probe)
return top, probe
@benchmark("Signal Source (Cosine)", "analog.sig_source_f")
def test_sig_source_cosine():
top = gr.top_block()
src = analog.sig_source_f(1e6, analog.GR_COS_WAVE, 200e3, 1.0)
probe = blocks.probe_rate(gr.sizeof_float)
top.connect(src, probe)
return top, probe
@benchmark("Signal Source (Square)", "analog.sig_source_f")
def test_sig_source_square():
top = gr.top_block()
src = analog.sig_source_f(1e6, analog.GR_SQR_WAVE, 200e3, 1.0)
probe = blocks.probe_rate(gr.sizeof_float)
top.connect(src, probe)
return top, probe
@benchmark("FIR Filter (Dotprod, 16 Real taps, Complex input)", "filter.fir_filter_ccf")
def test_fir_filter_ccf():
top = gr.top_block()
src = blocks.null_source(gr.sizeof_gr_complex)
firfilter = filter.fir_filter_ccf(1, [random.random() for _ in range(16)])
probe = blocks.probe_rate(gr.sizeof_gr_complex)
top.connect(src, firfilter, probe)
return top, probe
@benchmark("FIR Filter (Dotprod, 16 Real taps, Real input)", "filter.fir_filter_fff")
def test_fir_filter_fff():
top = gr.top_block()
src = blocks.null_source(gr.sizeof_float)
firfilter = filter.fir_filter_fff(1, [random.random() for _ in range(16)])
probe = blocks.probe_rate(gr.sizeof_float)
top.connect(src, firfilter, probe)
return top, probe
@benchmark("FIR Filter (Dotprod, 16 Complex taps, Complex input)", "filter.fir_filter_ccc")
def test_fir_filter_ccc():
top = gr.top_block()
src = blocks.null_source(gr.sizeof_gr_complex)
firfilter = filter.fir_filter_ccc(1, [complex(random.random(), random.random()) for _ in range(16)])
probe = blocks.probe_rate(gr.sizeof_gr_complex)
top.connect(src, firfilter, probe)
return top, probe
@benchmark("FIR Filter (FFT, 128 Real taps, Complex input)", "filter.fft_filter_ccf")
def test_fft_filter_ccf():
top = gr.top_block()
src = blocks.null_source(gr.sizeof_gr_complex)
firfilter = filter.fft_filter_ccf(1, [random.random() for _ in range(128)])
probe = blocks.probe_rate(gr.sizeof_gr_complex)
top.connect(src, firfilter, probe)
return top, probe
@benchmark("FIR Filter (FFT, 128 Real taps, Real input)", "filter.fft_filter_fff")
def test_fft_filter_fff():
top = gr.top_block()
src = blocks.null_source(gr.sizeof_float)
firfilter = filter.fft_filter_fff(1, [random.random() for _ in range(128)])
probe = blocks.probe_rate(gr.sizeof_float)
top.connect(src, firfilter, probe)
return top, probe
@benchmark("FIR Filter (FFT, 128 Complex taps, Complex input)", "filter.fft_filter_ccc")
def test_fft_filter_ccc():
top = gr.top_block()
src = blocks.null_source(gr.sizeof_gr_complex)
firfilter = filter.fft_filter_ccc(1, [complex(random.random(), random.random()) for _ in range(128)])
probe = blocks.probe_rate(gr.sizeof_gr_complex)
top.connect(src, firfilter, probe)
return top, probe
@benchmark("IIR Filter (5 ff 3 fb Real taps, Complex input)", "filter.iir_filter_ccf")
def test_iir_filter_ccf():
top = gr.top_block()
src = blocks.null_source(gr.sizeof_gr_complex)
iirfilter = filter.iir_filter_ccf([random.random() for _ in range(5)], [random.random() for _ in range(3)])
probe = blocks.probe_rate(gr.sizeof_gr_complex)
top.connect(src, iirfilter, probe)
return top, probe
@benchmark("FM Deemphasis Filter", "analog.fm_deemph")
def test_fm_deemph():
top = gr.top_block()
src = blocks.null_source(gr.sizeof_float)
deemph = analog.fm_deemph(30e3, 75e-6)
probe = blocks.probe_rate(gr.sizeof_float)
top.connect(src, deemph, probe)
return top, probe
@benchmark("Frequency Translator", "blocks.rotator_cc")
def test_rotator_cc():
top = gr.top_block()
src = blocks.null_source(gr.sizeof_gr_complex)
rotator = blocks.rotator_cc(2*math.pi*(200e3/1e6))
probe = blocks.probe_rate(gr.sizeof_gr_complex)
top.connect(src, rotator, probe)
return top, probe
@benchmark("Hilbert Transform (65 taps)", "filter.hilbert_fc")
def test_hilbert():
top = gr.top_block()
src = blocks.null_source(gr.sizeof_float)
hilbert = filter.hilbert_fc(65)
probe = blocks.probe_rate(gr.sizeof_gr_complex)
top.connect(src, hilbert, probe)
return top, probe
@benchmark("Hilbert Transform (129 taps)", "filter.hilbert_fc")
def test_hilbert():
top = gr.top_block()
src = blocks.null_source(gr.sizeof_float)
hilbert = filter.hilbert_fc(129)
probe = blocks.probe_rate(gr.sizeof_gr_complex)
top.connect(src, hilbert, probe)
return top, probe
@benchmark("Frequency Discriminator", "analog.quadrature_demod_cf")
def test_quadrature_demod_cf():
top = gr.top_block()
src = blocks.null_source(gr.sizeof_gr_complex)
fdisc = analog.quadrature_demod_cf(5.0)
probe = blocks.probe_rate(gr.sizeof_float)
top.connect(src, fdisc, probe)
return top, probe
@benchmark("PLL", "analog.pll_refout_cc")
def test_pll_refout_cc():
top = gr.top_block()
src = analog.fastnoise_source_c(analog.GR_UNIFORM, math.sqrt(2))
pll = analog.pll_refout_cc(2*math.pi*1e3/300e3, 2*math.pi*200e3/300e3, 2*math.pi*220e3/300)
probe = blocks.probe_rate(gr.sizeof_gr_complex)
top.connect(src, pll, probe)
return top, probe
@benchmark("Add (Complex)", "blocks.add_cc")
def test_add_cc():
top = gr.top_block()
src = blocks.null_source(gr.sizeof_gr_complex)
add = blocks.add_cc()
probe = blocks.probe_rate(gr.sizeof_gr_complex)
top.connect((src, 0), (add, 0))
top.connect((src, 0), (add, 1))
top.connect(add, probe)
return top, probe
@benchmark("Subtract (Complex)", "blocks.sub_cc")
def test_sub_cc():
top = gr.top_block()
src = blocks.null_source(gr.sizeof_gr_complex)
sub = blocks.sub_cc()
probe = blocks.probe_rate(gr.sizeof_gr_complex)
top.connect((src, 0), (sub, 0))
top.connect((src, 0), (sub, 1))
top.connect(sub, probe)
return top, probe
@benchmark("Multiply (Complex)", "blocks.multiply_cc")
def test_multiply_cc():
top = gr.top_block()
src = blocks.null_source(gr.sizeof_gr_complex)
mul = blocks.multiply_cc()
probe = blocks.probe_rate(gr.sizeof_gr_complex)
top.connect((src, 0), (mul, 0))
top.connect((src, 0), (mul, 1))
top.connect(mul, probe)
return top, probe
@benchmark("Multiply (Real)", "blocks.multiply_ff")
def test_multiply_ff():
top = gr.top_block()
src = blocks.null_source(gr.sizeof_float)
mul = blocks.multiply_ff()
probe = blocks.probe_rate(gr.sizeof_float)
top.connect((src, 0), (mul, 0))
top.connect((src, 0), (mul, 1))
top.connect(mul, probe)
return top, probe
@benchmark("Multiply Conjugate", "blocks.multiply_conjugate_cc")
def test_multiply_conjugate_cc():
top = gr.top_block()
src = blocks.null_source(gr.sizeof_gr_complex)
mul = blocks.multiply_conjugate_cc()
probe = blocks.probe_rate(gr.sizeof_gr_complex)
top.connect((src, 0), (mul, 0))
top.connect((src, 0), (mul, 1))
top.connect(mul, probe)
return top, probe
@benchmark("Multiply Constant (Complex constant, Complex input)", "blocks.multiply_const_cc")
def test_multiply_const_cc():
top = gr.top_block()
src = blocks.null_source(gr.sizeof_gr_complex)
mul = blocks.multiply_const_cc(complex(random.random(), random.random()))
probe = blocks.probe_rate(gr.sizeof_gr_complex)
top.connect(src, mul, probe)
return top, probe
@benchmark("Multiply Constant (Real constant, Real input)", "blocks.multiply_const_ff")
def test_multiply_const_ff():
top = gr.top_block()
src = blocks.null_source(gr.sizeof_float)
mul = blocks.multiply_const_ff(random.random())
probe = blocks.probe_rate(gr.sizeof_float)
top.connect(src, mul, probe)
return top, probe
@benchmark("Absolute Value", "blocks.abs_ff")
def test_abs_ff():
top = gr.top_block()
src = blocks.null_source(gr.sizeof_float)
abs = blocks.abs_ff()
probe = blocks.probe_rate(gr.sizeof_float)
top.connect(src, abs, probe)
return top, probe
@benchmark("Complex Conjugate", "blocks.conjugate_cc")
def test_conjugate_cc():
top = gr.top_block()
src = blocks.null_source(gr.sizeof_gr_complex)
conj = blocks.conjugate_cc()
probe = blocks.probe_rate(gr.sizeof_gr_complex)
top.connect(src, conj, probe)
return top, probe
@benchmark("Complex Magnitude", "blocks.complex_to_mag")
def test_complex_to_mag():
top = gr.top_block()
src = blocks.null_source(gr.sizeof_gr_complex)
mag = blocks.complex_to_mag()
probe = blocks.probe_rate(gr.sizeof_float)
top.connect(src, mag, probe)
return top, probe
@benchmark("Complex Phase", "blocks.complex_to_arg")
def test_complex_to_arg():
top = gr.top_block()
src = blocks.null_source(gr.sizeof_gr_complex)
arg = blocks.complex_to_arg()
probe = blocks.probe_rate(gr.sizeof_float)
top.connect(src, arg, probe)
return top, probe
@benchmark("Delay (N = 3000, Complex input)", "blocks.delay")
def test_delay():
top = gr.top_block()
src = blocks.null_source(gr.sizeof_gr_complex)
delay = blocks.delay(gr.sizeof_gr_complex, 3000)
probe = blocks.probe_rate(gr.sizeof_gr_complex)
top.connect(src, delay, probe)
return top, probe
@benchmark("Bit Slicer", "digtal.binary_slicer_fb")
def test_binary_slicer_fb():
top = gr.top_block()
src = analog.fastnoise_source_f(analog.GR_UNIFORM, math.sqrt(2))
slicer = digital.binary_slicer_fb()
probe = blocks.probe_rate(gr.sizeof_char)
top.connect(src, slicer, probe)
return top, probe
@benchmark("Differential Decoder", "digital.diff_decoder_bb")
def test_diff_decoder_bb():
top = gr.top_block()
src = digital.glfsr_source_b(7)
diffdecoder = digital.diff_decoder_bb(2)
probe = blocks.probe_rate(gr.sizeof_char)
top.connect(src, diffdecoder, probe)
return top, probe
@benchmark("Complex to Real", "blocks.complex_to_real")
def test_complex_to_real():
top = gr.top_block()
src = blocks.null_source(gr.sizeof_gr_complex)
complextoreal = blocks.complex_to_real()
probe = blocks.probe_rate(gr.sizeof_float)
top.connect(src, complextoreal, probe)
return top, probe
@benchmark("Complex to Imaginary", "blocks.complex_to_imag")
def test_complex_to_imag():
top = gr.top_block()
src = blocks.null_source(gr.sizeof_gr_complex)
complextoimag = blocks.complex_to_imag()
probe = blocks.probe_rate(gr.sizeof_float)
top.connect(src, complextoimag, probe)
return top, probe
@benchmark("Float to Complex", "blocks.float_to_complex")
def test_float_to_complex():
top = gr.top_block()
src = blocks.null_source(gr.sizeof_float)
floattocomplex = blocks.float_to_complex()
probe = blocks.probe_rate(gr.sizeof_gr_complex)
top.connect((src, 0), (floattocomplex, 0))
top.connect((src, 0), (floattocomplex, 1))
top.connect(floattocomplex, probe)
return top, probe
# Missing comparable blocks to:
# @benchmark("IQ File Source (f32le)", "IQFileSource")
# @benchmark("Real File Source (f32le)", "RealFileSource")
# @benchmark("IIR Filter (5 ff 3 fb Real taps, Real input)", "iir_filter_fff")
# @benchmark("Downsampler (M = 7), Complex", "DownsamplerBlock")
# @benchmark("Downsampler (M = 7), Real", "DownsamplerBlock")
# @benchmark("Upsampler (L = 7), Complex", "UpsamplerBlock")
# @benchmark("Upsampler (L = 7), Real", "UpsamplerBlock")
# @benchmark("Zero Crossing Clock Recovery", "ZeroCrossingClockRecoveryBlock")
# @benchmark("Binary Phase Corrector", "BinaryPhaseCorrectorBlock")
# @benchmark("Multiply Constant (Real constant, Complex input)", "blocks.multiply_const_cc")
################################################################################
# Benchmark runner
if __name__ == '__main__':
# If a test name was specified, filter the benchmark suite by fuzzy-matching
# by test name
if len(sys.argv) > 1:
MatchedBenchmarkSuite = []
for benchmark in BenchmarkSuite:
if benchmark[0].lower().find(sys.argv[1].lower()) >= 0:
MatchedBenchmarkSuite.append(benchmark)
BenchmarkSuite = MatchedBenchmarkSuite
benchmark_results = {
'version': gr.version(),
'parameters': {
'num_trials': BENCH_NUM_TRIALS,
'trial_duration': BENCH_TRIAL_DURATION
},
'benchmarks': []
}
for index, benchmark in enumerate(BenchmarkSuite):
test_name, block_name, test_factory = benchmark
sys.stderr.write("Running benchmark {}/{} \"{}\"\n".format(index+1, len(BenchmarkSuite), test_name))
samples_per_second, bytes_per_second = [], []
# Run each trial
for trial in range(BENCH_NUM_TRIALS):
# Create the test top block
test_top, test_probe = test_factory()
# Run the trial
test_top.start()
time.sleep(BENCH_TRIAL_DURATION)
test_top.stop()
trial_samples_per_second = test_probe.rate()
trial_bytes_per_second = trial_samples_per_second * test_probe.input_signature().sizeof_stream_item(0)
sys.stderr.write("\tTrial {} - {:.1f} MS/s, {:.1f} MiB/s\n".format(trial+1, trial_samples_per_second/1e6, trial_bytes_per_second/1048576))
samples_per_second.append(trial_samples_per_second)
bytes_per_second.append(trial_bytes_per_second)
# Compute means
mean_samples_per_second = sum(samples_per_second)/BENCH_NUM_TRIALS
mean_bytes_per_second = sum(bytes_per_second)/BENCH_NUM_TRIALS
# Compute standard deviations
stdev_samples_per_second = math.sqrt(sum([(e - mean_samples_per_second)**2 for e in samples_per_second])/BENCH_NUM_TRIALS)
stdev_bytes_per_second = math.sqrt(sum([(e - mean_bytes_per_second)**2 for e in bytes_per_second])/BENCH_NUM_TRIALS)
sys.stderr.write("\tAverage - {:.1f} MS/s, {:.1f} MiB/s\n".format(mean_samples_per_second/1e6, mean_bytes_per_second/1048576))
sys.stderr.write("\t Stdev - {:.1f} MS/s, {:.1f} MiB/s\n".format(stdev_samples_per_second/1e6, stdev_bytes_per_second/1048576))
# Add it to our table
benchmark_results['benchmarks'].append({
'name': test_name,
'block_name': block_name,
'results': {
'samples_per_second': mean_samples_per_second,
'samples_per_second_stdev': stdev_samples_per_second,
'bytes_per_second': mean_bytes_per_second
}
})
print(json.dumps(benchmark_results))