-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadaptive_decoder_benchmark.cpp
More file actions
77 lines (62 loc) · 2.15 KB
/
adaptive_decoder_benchmark.cpp
File metadata and controls
77 lines (62 loc) · 2.15 KB
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
#include <iostream>
#include <vector>
#include <chrono>
#include <string>
#include "encoder.hpp"
#include "decoder.hpp"
/*
Decoding is far faster than encoding (making this benchmark test seem moot).
This is because decoding does not involve any calculation of leading/trailing zeros.
Decoding is pure shifting and XORing operations, which the CPU can do extremely fast
resulting in sky-high throughputs.
This benchmarks thus only shows the read latency of the compressed data.
*/
void runBenchmark(const std::string &name, comp::Decoder &decoder, int count)
{
double out{};
double checksum{0.0}; // to force the cpu to do work so it doesn't skip loops.
auto start = std::chrono::high_resolution_clock::now();
for(int i{0}; i < count; ++i)
{
if(decoder.next(out))
{
checksum += out; //Force the compiler to keep this call.
}
}
auto end = std::chrono::high_resolution_clock::now();
auto time_len = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
if(checksum < 0.0) { std::cout << ""; } // Prevent compiler from optimizing away the loop
double throughput = (count / (time_len / 1e6)) / 1e6;
std::cout << name << " throughtput: " << throughput << " M ticks/sec.\n";
}
int main()
{
const int TICKS = 10000000;
std::vector<double> data(TICKS, 150.25);
for(int i{0}; i < TICKS; ++i)
{
if(i % 10 == 0)
{
data[i] += 0.05;
}
}
//Prep buffer
comp::Encoder encoder1(TICKS * 32); //Allocating extra space to avoid accidental overflow
comp::AdaptiveEncoder encoder2(TICKS * 32);
for(const auto &d : data)
{
encoder1.append(d);
encoder2.append(d);
}
//Flush buffers
encoder1.fin();
encoder2.fin();
//Benchmark decoders
//Basic decoder
comp::Decoder decoder1(encoder1.get_buffer().front(), encoder1.get_buffer().size());
runBenchmark("Basic Decoder", decoder1, TICKS);
//Adaptive Decoder
comp::AdaptiveDecoder decoder2(encoder2.get_buffer().front(), encoder2.get_buffer().size());
runBenchmark("Adaptive Decoder", decoder2, TICKS);
return 0;
}