-
Notifications
You must be signed in to change notification settings - Fork 1
/
biquad_kfr.hpp
60 lines (57 loc) · 1.98 KB
/
biquad_kfr.hpp
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
/**
* FFT bencmarking tool (http://kfrlib.com)
* Copyright (C) 2016 D Levin
* Benchmark source code is dual-licensed under MIT and GPL 2 or later
* See LICENSE.txt for details
*/
#pragma once
#include "benchmark.hpp"
#include "biquad.h"
#include "kfr/base/univector.hpp"
#include "kfr/dsp/biquad.hpp"
#include "kfr/expressions/pointer.hpp"
#include "kfr/misc/random.hpp"
#include "kfr/version.hpp"
#include <string>
class dsp_benchmark
{
public:
dsp_benchmark(const char* param) : count(std::atol(param)), out(biquad_size), in(biquad_size)
{
cometa::cswitch(
cometa::csizes<1, 2, 4, 8, 16, 32, 64>, count,
[this](auto count) {
kfr::biquad_params<real> bq[count];
for (size_t i = 0; i < count; i++)
bq[i] = kfr::biquad_notch<real>((i + 1.0) * 0.5 / (count + 2), 0.5);
constexpr size_t w = count >= 8 ? kfr::vector_width<real, kfr::cpu_t::native> : 0;
if (count == 1)
{
this->func = [this, bq]() mutable {
kfr::process<real, kfr::cpu_t::native, w>(out, kfr::biquad(bq[0], in), biquad_size);
};
}
else
{
this->func = [this, bq]() mutable {
kfr::process<real, kfr::cpu_t::native, w>(out, kfr::biquad(bq, in), biquad_size);
};
}
},
[param]() {
printf("Invalid param: %s\n", param);
std::abort();
});
}
static std::string name() { return kfr::library_version(); }
static std::string shortname() { return "KFR"; }
void before() { fill_random(0, in.data(), biquad_size); }
void after() { dont_optimize(out.data()); }
void execute() { func(); }
~dsp_benchmark() {}
private:
size_t count;
kfr::univector<real> out;
kfr::univector<real> in;
cometa::function<void()> func;
};