-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathluaradio_benchmark.lua
755 lines (714 loc) · 25.1 KB
/
luaradio_benchmark.lua
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
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
local ffi = require('ffi')
local json = require('radio.thirdparty.json')
local buffer = require('tests.buffer')
local radio = require('radio')
-- Benchmark parameters
-- Duration of each benchmark trial
local BENCH_TRIAL_DURATION = 5
-- Number of benchmark trials to average
local BENCH_NUM_TRIALS = 5
-- Benchmark suite
local BenchmarkSuite = {
{
"Five Back to Back FIR Filters (FFT, 256 Real taps, Complex input)",
"FIRFilterBlock",
function (results_fd)
local taps = {}
for i = 1, 256 do
taps[i] = math.random(1.0)
end
taps = radio.types.Float32.vector_from_array(taps)
return radio.CompositeBlock():connect(
radio.ZeroSource(radio.types.ComplexFloat32, 1.0),
radio.FIRFilterBlock(taps, true),
radio.FIRFilterBlock(taps, true),
radio.FIRFilterBlock(taps, true),
radio.FIRFilterBlock(taps, true),
radio.FIRFilterBlock(taps, true),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"Zero Source (Complex)",
"ZeroSource",
function (results_fd)
return radio.CompositeBlock():connect(
radio.ZeroSource(radio.types.ComplexFloat32, 1.0),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"Zero Source (Real)",
"ZeroSource",
function (results_fd)
return radio.CompositeBlock():connect(
radio.ZeroSource(radio.types.Float32, 1.0),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"IQ File Source (f32le)",
"IQFileSource",
function (results_fd)
local random_vec = radio.types.ComplexFloat32.vector(262144)
for i = 0, random_vec.length-1 do
random_vec.data[i].real = 2*math.random(1.0)-1.0
random_vec.data[i].imag = 2*math.random(1.0)-1.0
end
local src_fd = buffer.open(ffi.string(random_vec.data, random_vec.size))
return radio.CompositeBlock():connect(
radio.IQFileSource(src_fd, 'f32le', 1.0, true),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"Real File Source (f32le)",
"RealFileSource",
function (results_fd)
local random_vec = radio.types.Float32.vector(262144)
for i = 0, random_vec.length-1 do
random_vec.data[i].value = 2*math.random(1.0)-1.0
end
local src_fd = buffer.open(ffi.string(random_vec.data, random_vec.size))
return radio.CompositeBlock():connect(
radio.RealFileSource(src_fd, 'f32le', 1.0, true),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"Raw File Source (float)",
"RawFileSource",
function (results_fd)
local random_vec = radio.types.Float32.vector(262144)
for i = 0, random_vec.length-1 do
random_vec.data[i].value = 2*math.random(1.0)-1.0
end
local src_fd = buffer.open(ffi.string(random_vec.data, random_vec.size))
return radio.CompositeBlock():connect(
radio.RawFileSource(src_fd, radio.types.Float32, 1.0, true),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"Uniform Random Source (Complex)",
"UniformRandomSource",
function (results_fd)
return radio.CompositeBlock():connect(
radio.UniformRandomSource(radio.types.ComplexFloat32, 1.0),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"Uniform Random Source (Real)",
"UniformRandomSource",
function (results_fd)
return radio.CompositeBlock():connect(
radio.UniformRandomSource(radio.types.Float32, 1.0),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"Signal Source (Complex Exponential)",
"SignalSource",
function (results_fd)
return radio.CompositeBlock():connect(
radio.SignalSource('exponential', 200e3, 1e6),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"Signal Source (Cosine)",
"SignalSource",
function (results_fd)
return radio.CompositeBlock():connect(
radio.SignalSource('cosine', 200e3, 1e6),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"Signal Source (Square)",
"SignalSource",
function (results_fd)
return radio.CompositeBlock():connect(
radio.SignalSource('square', 200e3, 1e6),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"FIR Filter (Dotprod, 16 Real taps, Complex input)",
"FIRFilterBlock",
function (results_fd)
local taps = {}
for i = 1, 16 do
taps[i] = math.random(1.0)
end
taps = radio.types.Float32.vector_from_array(taps)
return radio.CompositeBlock():connect(
radio.ZeroSource(radio.types.ComplexFloat32, 1.0),
radio.FIRFilterBlock(taps, false),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"FIR Filter (Dotprod, 16 Real taps, Real input)",
"FIRFilterBlock",
function (results_fd)
local taps = {}
for i = 1, 16 do
taps[i] = math.random(1.0)
end
taps = radio.types.Float32.vector_from_array(taps)
return radio.CompositeBlock():connect(
radio.ZeroSource(radio.types.Float32, 1.0),
radio.FIRFilterBlock(taps, false),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"FIR Filter (Dotprod, 16 Complex taps, Complex input)",
"FIRFilterBlock",
function (results_fd)
local taps = {}
for i = 1, 16 do
taps[i] = {math.random(1.0), math.random(1.0)}
end
taps = radio.types.ComplexFloat32.vector_from_array(taps)
return radio.CompositeBlock():connect(
radio.ZeroSource(radio.types.ComplexFloat32, 1.0),
radio.FIRFilterBlock(taps, false),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"FIR Filter (FFT, 128 Real taps, Complex input)",
"FIRFilterBlock",
function (results_fd)
local taps = {}
for i = 1, 128 do
taps[i] = math.random(1.0)
end
taps = radio.types.Float32.vector_from_array(taps)
return radio.CompositeBlock():connect(
radio.ZeroSource(radio.types.ComplexFloat32, 1.0),
radio.FIRFilterBlock(taps, true),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"FIR Filter (FFT, 128 Real taps, Real input)",
"FIRFilterBlock",
function (results_fd)
local taps = {}
for i = 1, 128 do
taps[i] = math.random(1.0)
end
taps = radio.types.Float32.vector_from_array(taps)
return radio.CompositeBlock():connect(
radio.ZeroSource(radio.types.Float32, 1.0),
radio.FIRFilterBlock(taps, true),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"FIR Filter (FFT, 128 Complex taps, Complex input)",
"FIRFilterBlock",
function (results_fd)
local taps = {}
for i = 1, 128 do
taps[i] = {math.random(1.0), math.random(1.0)}
end
taps = radio.types.ComplexFloat32.vector_from_array(taps)
return radio.CompositeBlock():connect(
radio.ZeroSource(radio.types.ComplexFloat32, 1.0),
radio.FIRFilterBlock(taps, true),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"IIR Filter (5 ff 3 fb Real taps, Complex input)",
"IIRFilterBlock",
function (results_fd)
local b_taps = {math.random(1.0), math.random(1.0), math.random(1.0), math.random(1.0)}
local a_taps = {math.random(1.0), math.random(1.0), math.random(1.0)}
return radio.CompositeBlock():connect(
radio.ZeroSource(radio.types.ComplexFloat32, 1.0),
radio.IIRFilterBlock(b_taps, a_taps),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"IIR Filter (5 ff 3 fb Real taps, Real input)",
"IIRFilterBlock",
function (results_fd)
local b_taps = {math.random(1.0), math.random(1.0), math.random(1.0), math.random(1.0)}
local a_taps = {math.random(1.0), math.random(1.0), math.random(1.0)}
return radio.CompositeBlock():connect(
radio.ZeroSource(radio.types.Float32, 1.0),
radio.IIRFilterBlock(b_taps, a_taps),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"FM Deemphasis Filter",
"FMDeemphasisFilterBlock",
function (results_fd)
return radio.CompositeBlock():connect(
radio.ZeroSource(radio.types.Float32, 30e3),
radio.FMDeemphasisFilterBlock(75e-6),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"Downsampler (M = 5), Complex",
"DownsamplerBlock",
function (results_fd)
return radio.CompositeBlock():connect(
radio.ZeroSource(radio.types.ComplexFloat32, 1.0),
radio.DownsamplerBlock(5),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"Downsampler (M = 5), Real",
"DownsamplerBlock",
function (results_fd)
return radio.CompositeBlock():connect(
radio.ZeroSource(radio.types.Float32, 1.0),
radio.DownsamplerBlock(5),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"Upsampler (L = 3), Complex",
"UpsamplerBlock",
function (results_fd)
return radio.CompositeBlock():connect(
radio.ZeroSource(radio.types.ComplexFloat32, 1.0),
radio.UpsamplerBlock(3),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"Upsampler (L = 3), Real",
"UpsamplerBlock",
function (results_fd)
return radio.CompositeBlock():connect(
radio.ZeroSource(radio.types.Float32, 1.0),
radio.UpsamplerBlock(3),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"Frequency Translator",
"FrequencyTranslatorBlock",
function (results_fd)
return radio.CompositeBlock():connect(
radio.ZeroSource(radio.types.ComplexFloat32, 1e6),
radio.FrequencyTranslatorBlock(200e3),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"Hilbert Transform (65 taps)",
"HilbertTransformBlock",
function (results_fd)
return radio.CompositeBlock():connect(
radio.ZeroSource(radio.types.Float32, 1.0),
radio.HilbertTransformBlock(65),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"Hilbert Transform (129 taps)",
"HilbertTransformBlock",
function (results_fd)
return radio.CompositeBlock():connect(
radio.ZeroSource(radio.types.Float32, 1.0),
radio.HilbertTransformBlock(129),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"Frequency Discriminator",
"FrequencyDiscriminatorBlock",
function (results_fd)
return radio.CompositeBlock():connect(
radio.ZeroSource(radio.types.ComplexFloat32, 1.0),
radio.FrequencyDiscriminatorBlock(1.25),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"PLL",
"PLLBlock",
function (results_fd)
local src = radio.UniformRandomSource(radio.types.ComplexFloat32, 1e6)
local pll = radio.PLLBlock(1e3, 200e3, 220e3)
local sink = radio.BenchmarkSink(results_fd, true)
local top = radio.CompositeBlock()
top:connect(src, pll)
top:connect(pll, 'out', sink, 'in')
return top
end
},
{
"Zero Crossing Clock Recovery",
"ZeroCrossingClockRecoveryBlock",
function (results_fd)
return radio.CompositeBlock():connect(
radio.UniformRandomSource(radio.types.Float32, 1e6),
radio.ZeroCrossingClockRecoveryBlock(1200),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"Binary Phase Corrector",
"BinaryPhaseCorrectorBlock",
function (results_fd)
return radio.CompositeBlock():connect(
radio.UniformRandomSource(radio.types.ComplexFloat32, 1.0),
radio.BinaryPhaseCorrectorBlock(3000),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"Add (Complex)",
"AddBlock",
function (results_fd)
local src = radio.ZeroSource(radio.types.ComplexFloat32, 1.0)
local adder = radio.AddBlock()
local top = radio.CompositeBlock()
top:connect(src, 'out', adder, 'in1')
top:connect(src, 'out', adder, 'in2')
return top:connect(adder, radio.BenchmarkSink(results_fd, true))
end
},
{
"Subtract (Complex)",
"SubtractBlock",
function (results_fd)
local src = radio.ZeroSource(radio.types.ComplexFloat32, 1.0)
local subtractor = radio.SubtractBlock()
local top = radio.CompositeBlock()
top:connect(src, 'out', subtractor, 'in1')
top:connect(src, 'out', subtractor, 'in2')
return top:connect(subtractor, radio.BenchmarkSink(results_fd, true))
end
},
{
"Multiply (Complex)",
"MultiplyBlock",
function (results_fd)
local src = radio.ZeroSource(radio.types.ComplexFloat32, 1.0)
local multiplier = radio.MultiplyBlock()
local top = radio.CompositeBlock()
top:connect(src, 'out', multiplier, 'in1')
top:connect(src, 'out', multiplier, 'in2')
return top:connect(multiplier, radio.BenchmarkSink(results_fd, true))
end
},
{
"Multiply (Real)",
"MultiplyBlock",
function (results_fd)
local src = radio.ZeroSource(radio.types.Float32, 1.0)
local multiplier = radio.MultiplyBlock()
local top = radio.CompositeBlock()
top:connect(src, 'out', multiplier, 'in1')
top:connect(src, 'out', multiplier, 'in2')
return top:connect(multiplier, radio.BenchmarkSink(results_fd, true))
end
},
{
"Multiply Conjugate",
"MultiplyConjugateBlock",
function (results_fd)
local src = radio.ZeroSource(radio.types.ComplexFloat32, 1.0)
local multiplier = radio.MultiplyConjugateBlock()
local top = radio.CompositeBlock()
top:connect(src, 'out', multiplier, 'in1')
top:connect(src, 'out', multiplier, 'in2')
return top:connect(multiplier, radio.BenchmarkSink(results_fd, true))
end
},
{
"Multiply Constant (Real constant, Complex input)",
"MultiplyConstantBlock",
function (results_fd)
return radio.CompositeBlock():connect(
radio.ZeroSource(radio.types.ComplexFloat32, 1.0),
radio.MultiplyConstantBlock(5.0),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"Multiply Constant (Complex constant, Complex input)",
"MultiplyConstantBlock",
function (results_fd)
return radio.CompositeBlock():connect(
radio.ZeroSource(radio.types.ComplexFloat32, 1.0),
radio.MultiplyConstantBlock(radio.types.ComplexFloat32(math.random(), math.random())),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"Multiply Constant (Real constant, Real input)",
"MultiplyConstantBlock",
function (results_fd)
return radio.CompositeBlock():connect(
radio.ZeroSource(radio.types.Float32, 1.0),
radio.MultiplyConstantBlock(5.0),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"Absolute Value",
"AbsoluteValueBlock",
function (results_fd)
return radio.CompositeBlock():connect(
radio.ZeroSource(radio.types.Float32, 1.0),
radio.AbsoluteValueBlock(),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"Complex Conjugate",
"ComplexConjugateBlock",
function (results_fd)
return radio.CompositeBlock():connect(
radio.ZeroSource(radio.types.ComplexFloat32, 1.0),
radio.ComplexConjugateBlock(),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"Complex Magnitude",
"ComplexMagnitudeBlock",
function (results_fd)
return radio.CompositeBlock():connect(
radio.ZeroSource(radio.types.ComplexFloat32, 1.0),
radio.ComplexMagnitudeBlock(),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"Complex Phase",
"ComplexPhaseBlock",
function (results_fd)
return radio.CompositeBlock():connect(
radio.ZeroSource(radio.types.ComplexFloat32, 1.0),
radio.ComplexPhaseBlock(),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"Delay (N = 3000, Complex input)",
"DelayBlock",
function (results_fd)
return radio.CompositeBlock():connect(
radio.ZeroSource(radio.types.ComplexFloat32, 1.0),
radio.DelayBlock(3000),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"Bit Slicer",
"SlicerBlock",
function (results_fd)
return radio.CompositeBlock():connect(
radio.UniformRandomSource(radio.types.Float32, 1.0),
radio.SlicerBlock(),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"Differential Decoder",
"DifferentialDecoderBlock",
function (results_fd)
return radio.CompositeBlock():connect(
radio.UniformRandomSource(radio.types.Bit, 1.0),
radio.DifferentialDecoderBlock(),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"Complex to Real",
"ComplexToRealBlock",
function (results_fd)
return radio.CompositeBlock():connect(
radio.ZeroSource(radio.types.ComplexFloat32, 1.0),
radio.ComplexToRealBlock(),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"Complex to Imaginary",
"ComplexToImagBlock",
function (results_fd)
return radio.CompositeBlock():connect(
radio.ZeroSource(radio.types.ComplexFloat32, 1.0),
radio.ComplexToImagBlock(),
radio.BenchmarkSink(results_fd, true)
)
end
},
{
"Float to Complex",
"FloatToComplexBlock",
function (results_fd)
local src = radio.ZeroSource(radio.types.Float32, 1.0)
local floattocomplex = radio.FloatToComplexBlock()
local top = radio.CompositeBlock()
top:connect(src, 'out', floattocomplex, 'real')
top:connect(src, 'out', floattocomplex, 'imag')
return top:connect(floattocomplex, radio.BenchmarkSink(results_fd, true))
end
},
}
--------------------------------------------------------------------------------
-- Benchmark runner
local test_name_match = arg[1]
-- If a test name was specified, filter the benchmark suite
-- by fuzzy-matching by test name
if test_name_match then
local MatchedBenchmarkSuite = {}
for _, benchmark in ipairs(BenchmarkSuite) do
local test_name = benchmark[1]
if test_name:lower():find(test_name_match:lower(), 1, true) then
MatchedBenchmarkSuite[#MatchedBenchmarkSuite + 1] = benchmark
end
end
BenchmarkSuite = MatchedBenchmarkSuite
end
-- Results
local benchmark_results = {
version = radio.version,
platform = {
luajit_version = radio.platform.luajit_version,
os = radio.platform.os,
arch = radio.platform.arch,
page_size = radio.platform.page_size,
cpu_count = radio.platform.cpu_count,
cpu_model = radio.platform.cpu_model,
features = radio.platform.features,
versions = radio.platform.versions
},
parameters = {
num_trials = BENCH_NUM_TRIALS,
trial_duration = BENCH_TRIAL_DURATION,
},
benchmarks = {}
}
ffi.cdef[[
unsigned alarm(unsigned seconds);
]]
-- Block SIGINT and SIGALRM so we can catch them with sigwait()
local sigset = ffi.new("sigset_t[1]")
ffi.C.sigemptyset(sigset)
ffi.C.sigaddset(sigset, ffi.C.SIGINT)
ffi.C.sigaddset(sigset, ffi.C.SIGALRM)
if ffi.C.sigprocmask(ffi.C.SIG_BLOCK, sigset, nil) ~= 0 then
error("sigprocmask(): " .. ffi.string(ffi.C.strerror(ffi.errno())))
end
for index, benchmark in ipairs(BenchmarkSuite) do
local test_name, block_name, test_factory = unpack(benchmark)
io.stderr:write(string.format("Running benchmark %d/%d \"%s\"\n", index, #BenchmarkSuite, test_name))
local samples_per_second, bytes_per_second = {}, {}
local sig = ffi.new("int[1]")
-- Run each trial
for trial = 1, BENCH_NUM_TRIALS do
-- Create results buffer
local results_fd = buffer.open()
-- Create the test top block
local top = test_factory(results_fd)
-- Run the trial
top:start()
ffi.C.alarm(BENCH_TRIAL_DURATION)
if ffi.C.sigwait(sigset, sig) ~= 0 then
error("sigwait(): " .. ffi.string(ffi.C.strerror(ffi.errno())))
end
top:stop()
-- Check for user abort
if sig[0] == ffi.C.SIGINT then
io.stderr:write("Caught SIGINT, aborting...\n")
os.exit(0)
end
-- Read and deserialize results buffer
buffer.rewind(results_fd)
local results = json.decode(buffer.read(results_fd, 256))
buffer.close(results_fd)
io.stderr:write(string.format("\tTrial %d - %.1f MS/s, %.1f MiB/s\n", trial, results.samples_per_second/1e6, results.bytes_per_second/1048576))
samples_per_second[#samples_per_second + 1] = results.samples_per_second
bytes_per_second[#bytes_per_second + 1] = results.bytes_per_second
end
-- Compute means
local mean_samples_per_second, mean_bytes_per_second = 0.0, 0.0
for i = 1, BENCH_NUM_TRIALS do
mean_samples_per_second = mean_samples_per_second + samples_per_second[i]
mean_bytes_per_second = mean_bytes_per_second + bytes_per_second[i]
end
mean_samples_per_second = mean_samples_per_second / BENCH_NUM_TRIALS
mean_bytes_per_second = mean_bytes_per_second / BENCH_NUM_TRIALS
-- Compute standard deviations
local stdev_samples_per_second, stdev_bytes_per_second = 0.0, 0.0
for i = 1, BENCH_NUM_TRIALS do
stdev_samples_per_second = stdev_samples_per_second + (samples_per_second[i] - mean_samples_per_second)^2
stdev_bytes_per_second = stdev_bytes_per_second + (bytes_per_second[i] - mean_bytes_per_second)^2
end
stdev_samples_per_second = math.sqrt(stdev_samples_per_second / BENCH_NUM_TRIALS)
stdev_bytes_per_second = math.sqrt(stdev_bytes_per_second / BENCH_NUM_TRIALS)
io.stderr:write(string.format("\tAverage - %.1f MS/s, %.1f MiB/s\n", mean_samples_per_second/1e6, mean_bytes_per_second/1048576))
io.stderr:write(string.format("\t Stdev - %.1f MS/s, %.1f MiB/s\n", stdev_samples_per_second/1e6, stdev_bytes_per_second/1048576))
-- Add it to our table
benchmark_results.benchmarks[index] = {
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
}
}
end
print(json.encode(benchmark_results))