Created
July 9, 2018 16:26
-
-
Save carpikes/cad029c338605f70d9f687aeee447db4 to your computer and use it in GitHub Desktop.
HackRF source benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Compile using $(CC) -Ofast -march=native benchmark.cc -o benchmark | |
#include <chrono> | |
#include <complex> | |
#include <iostream> | |
#include <vector> | |
using hc_t = std::chrono::high_resolution_clock; | |
int main(int argc, char *argv[]) { | |
std::vector<std::complex<float>> _lut; | |
std::vector<uint16_t> inBuf(100 * 256 * 1024); | |
std::vector<std::complex<float>> outBuf(100 * 256 * 1024); | |
for (size_t i = 0; i <= 0xffff; i++) | |
_lut.push_back(std::complex<float>((i >> 8) * (1.f / 128.0f), | |
(i & 0xff) * (1.f / 128.f))); | |
for (auto &i : inBuf) i = rand(); | |
uint64_t ct1 = 0, ct2 = 0; | |
while (1) { | |
auto tp = hc_t::now(); | |
for (size_t i = 0; i < outBuf.size(); i++) outBuf[i] = _lut[inBuf[i]]; | |
auto t2 = hc_t::now() - tp; | |
const int8_t *a = (int8_t *)(uint16_t *)(&inBuf[0]); | |
tp = hc_t::now(); // reset ctr | |
for (size_t i = 0; i < outBuf.size(); i++) { | |
outBuf[i] = | |
std::complex<float>(a[i * 2] / 128.f, a[i * 2 + 1] / 128.f); | |
} | |
auto t3 = hc_t::now() - tp; | |
ct1 += t2.count(); | |
ct2 += t3.count(); | |
float ratio1 = float(t2.count()) / float(t3.count()); | |
float ratio2 = float(ct1) / float(ct2); | |
std::cout << "Speedup: " << ratio1 << "(" << ratio2 << ") \r"; | |
fflush(stdout); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment