|
1 | 1 | #include <benchmark/benchmark.h> |
2 | 2 |
|
3 | | -#include "../src/lz_string.hpp" |
| 3 | +#include "../includes/lz_string.hpp" |
4 | 4 | #include "../test_src/utilities.hpp" |
5 | 5 |
|
6 | 6 | #define NUM_ITER 100'000 |
7 | 7 |
|
8 | 8 | static std::string hello_world = |
9 | | - get_text_file_content("test_src/data/hello_world/data.bin"); |
| 9 | + get_text_file_content("test_src/data/hello_world/data.bin"); |
10 | 10 | static std::string all_ascii = |
11 | | - get_text_file_content("test_src/data/all_ascii/data.bin"); |
| 11 | + get_text_file_content("test_src/data/all_ascii/data.bin"); |
12 | 12 | static std::string temp_json = |
13 | | - get_text_file_content("test_src/data/temp_json/data.bin"); |
| 13 | + get_text_file_content("test_src/data/temp_json/data.bin"); |
14 | 14 | static std::string temp_json_float = |
15 | | - get_text_file_content("test_src/data/temp_json_float/data.bin"); |
| 15 | + get_text_file_content("test_src/data/temp_json_float/data.bin"); |
16 | 16 | static std::string lorem_ipsum = |
17 | | - get_text_file_content("test_src/data/lorem_ipsum/data.bin"); |
18 | | -static std::string pi = |
19 | | - get_text_file_content("test_src/data/pi/data.bin"); |
| 17 | + get_text_file_content("test_src/data/lorem_ipsum/data.bin"); |
| 18 | +static std::string pi = get_text_file_content("test_src/data/pi/data.bin"); |
20 | 19 | static std::string repeated = |
21 | | - get_text_file_content("test_src/data/repeated/data.bin"); |
| 20 | + get_text_file_content("test_src/data/repeated/data.bin"); |
22 | 21 | static std::string tattoo = |
23 | | - get_text_file_content("test_src/data/tattoo/data.bin"); |
| 22 | + get_text_file_content("test_src/data/tattoo/data.bin"); |
24 | 23 |
|
25 | 24 | /* |
26 | | -* --------------------------------------------------------------------------------------------------- |
27 | | -* -- Compress benchmarks |
28 | | -*/ |
29 | | - |
30 | | -#define MAKE_COMPRESS_BENCHMARK(func, inputs) \ |
31 | | -static void BM_##func##_##inputs(benchmark::State& state) { \ |
32 | | - auto input = pxd::lz_string::to_utf16(inputs); \ |
33 | | - \ |
34 | | - for(auto _ : state) { \ |
35 | | - auto compressed = pxd::lz_string::func(input); \ |
36 | | - } \ |
37 | | -} \ |
38 | | -BENCHMARK(BM_##func##_##inputs)->Iterations(NUM_ITER); |
| 25 | + * --------------------------------------------------------------------------------------------------- |
| 26 | + * -- Compress benchmarks |
| 27 | + */ |
| 28 | + |
| 29 | +#define MAKE_COMPRESS_BENCHMARK(func, inputs) \ |
| 30 | + static void BM_##func##_##inputs(benchmark::State& state) \ |
| 31 | + { \ |
| 32 | + auto input = pxd::lz_string::to_utf16(inputs); \ |
| 33 | + \ |
| 34 | + for (auto _ : state) { \ |
| 35 | + auto compressed = pxd::lz_string::func(input); \ |
| 36 | + } \ |
| 37 | + } \ |
| 38 | + BENCHMARK(BM_##func##_##inputs)->Iterations(NUM_ITER); |
39 | 39 |
|
40 | 40 | MAKE_COMPRESS_BENCHMARK(compress, hello_world); |
41 | 41 | MAKE_COMPRESS_BENCHMARK(compress, all_ascii); |
@@ -85,16 +85,19 @@ MAKE_COMPRESS_BENCHMARK(compressUint8Array, tattoo); |
85 | 85 | /* |
86 | 86 | * --------------------------------------------------------------------------------------------------- |
87 | 87 | * -- Decompress benchmarks |
88 | | -*/ |
89 | | - |
90 | | -#define MAKE_DECOMPRESS_BENCHMARK(compressfunc, decompressfunc, inputs) \ |
91 | | - static void BM_decompress_##decompressfunc##_##inputs(benchmark::State& state) { \ |
92 | | - auto compressed = pxd::lz_string::compressfunc(pxd::lz_string::to_utf16(inputs)); \ |
93 | | - \ |
94 | | - for(auto _ : state) { \ |
95 | | - auto decompressed = pxd::lz_string::decompressfunc(compressed); \ |
96 | | - } \ |
97 | | - } \ |
| 88 | + */ |
| 89 | + |
| 90 | +#define MAKE_DECOMPRESS_BENCHMARK(compressfunc, decompressfunc, inputs) \ |
| 91 | + static void BM_decompress_##decompressfunc##_##inputs( \ |
| 92 | + benchmark::State& state) \ |
| 93 | + { \ |
| 94 | + auto compressed = \ |
| 95 | + pxd::lz_string::compressfunc(pxd::lz_string::to_utf16(inputs)); \ |
| 96 | + \ |
| 97 | + for (auto _ : state) { \ |
| 98 | + auto decompressed = pxd::lz_string::decompressfunc(compressed); \ |
| 99 | + } \ |
| 100 | + } \ |
98 | 101 | BENCHMARK(BM_decompress_##decompressfunc##_##inputs)->Iterations(NUM_ITER); |
99 | 102 |
|
100 | 103 | MAKE_DECOMPRESS_BENCHMARK(compress, decompress, hello_world); |
@@ -124,20 +127,32 @@ MAKE_DECOMPRESS_BENCHMARK(compressBase64, decompressBase64, pi); |
124 | 127 | MAKE_DECOMPRESS_BENCHMARK(compressBase64, decompressBase64, repeated); |
125 | 128 | MAKE_DECOMPRESS_BENCHMARK(compressBase64, decompressBase64, tattoo); |
126 | 129 |
|
127 | | -MAKE_DECOMPRESS_BENCHMARK(compressEncodedURI, decompressEncodedURI, hello_world); |
| 130 | +MAKE_DECOMPRESS_BENCHMARK(compressEncodedURI, |
| 131 | + decompressEncodedURI, |
| 132 | + hello_world); |
128 | 133 | MAKE_DECOMPRESS_BENCHMARK(compressEncodedURI, decompressEncodedURI, all_ascii); |
129 | 134 | MAKE_DECOMPRESS_BENCHMARK(compressEncodedURI, decompressEncodedURI, temp_json); |
130 | | -MAKE_DECOMPRESS_BENCHMARK(compressEncodedURI, decompressEncodedURI, temp_json_float); |
131 | | -MAKE_DECOMPRESS_BENCHMARK(compressEncodedURI, decompressEncodedURI, lorem_ipsum); |
| 135 | +MAKE_DECOMPRESS_BENCHMARK(compressEncodedURI, |
| 136 | + decompressEncodedURI, |
| 137 | + temp_json_float); |
| 138 | +MAKE_DECOMPRESS_BENCHMARK(compressEncodedURI, |
| 139 | + decompressEncodedURI, |
| 140 | + lorem_ipsum); |
132 | 141 | MAKE_DECOMPRESS_BENCHMARK(compressEncodedURI, decompressEncodedURI, pi); |
133 | 142 | MAKE_DECOMPRESS_BENCHMARK(compressEncodedURI, decompressEncodedURI, repeated); |
134 | 143 | MAKE_DECOMPRESS_BENCHMARK(compressEncodedURI, decompressEncodedURI, tattoo); |
135 | 144 |
|
136 | | -MAKE_DECOMPRESS_BENCHMARK(compressUint8Array, decompressUint8Array, hello_world); |
| 145 | +MAKE_DECOMPRESS_BENCHMARK(compressUint8Array, |
| 146 | + decompressUint8Array, |
| 147 | + hello_world); |
137 | 148 | MAKE_DECOMPRESS_BENCHMARK(compressUint8Array, decompressUint8Array, all_ascii); |
138 | 149 | MAKE_DECOMPRESS_BENCHMARK(compressUint8Array, decompressUint8Array, temp_json); |
139 | | -MAKE_DECOMPRESS_BENCHMARK(compressUint8Array, decompressUint8Array, temp_json_float); |
140 | | -MAKE_DECOMPRESS_BENCHMARK(compressUint8Array, decompressUint8Array, lorem_ipsum); |
| 150 | +MAKE_DECOMPRESS_BENCHMARK(compressUint8Array, |
| 151 | + decompressUint8Array, |
| 152 | + temp_json_float); |
| 153 | +MAKE_DECOMPRESS_BENCHMARK(compressUint8Array, |
| 154 | + decompressUint8Array, |
| 155 | + lorem_ipsum); |
141 | 156 | MAKE_DECOMPRESS_BENCHMARK(compressUint8Array, decompressUint8Array, pi); |
142 | 157 | MAKE_DECOMPRESS_BENCHMARK(compressUint8Array, decompressUint8Array, repeated); |
143 | 158 | MAKE_DECOMPRESS_BENCHMARK(compressUint8Array, decompressUint8Array, tattoo); |
|
0 commit comments