summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorHans Kristian Rosbach <hk-git@circlestorm.org>2026-01-14 21:18:56 +0100
committerHans Kristian Rosbach <hk-github@circlestorm.org>2026-01-20 22:59:40 +0100
commitb7cd3d8d8589ad061b04fcb519e2c2d0212483f7 (patch)
tree3f481336d0f8576e6a083f32dca308f3fff68143 /test
parentb233f8675b08220aa0db9207cb4295df871299fd (diff)
downloadProject-Tick-b7cd3d8d8589ad061b04fcb519e2c2d0212483f7.tar.gz
Project-Tick-b7cd3d8d8589ad061b04fcb519e2c2d0212483f7.zip
Unify compare256/compare256_rle benchmarks and add rolling misalignment
Diffstat (limited to 'test')
-rw-r--r--test/benchmarks/benchmark_compare256.cc43
-rw-r--r--test/benchmarks/benchmark_compare256_rle.cc45
2 files changed, 53 insertions, 35 deletions
diff --git a/test/benchmarks/benchmark_compare256.cc b/test/benchmarks/benchmark_compare256.cc
index 6853ca2b1d..4b616f5a52 100644
--- a/test/benchmarks/benchmark_compare256.cc
+++ b/test/benchmarks/benchmark_compare256.cc
@@ -3,19 +3,16 @@
* For conditions of distribution and use, see copyright notice in zlib.h
*/
-#include <stdio.h>
-
#include <benchmark/benchmark.h>
extern "C" {
# include "zbuild.h"
-# include "zutil_p.h"
# include "arch_functions.h"
# include "../test_cpu_features.h"
# include "arch/generic/compare256_p.h"
}
-#define MAX_COMPARE_SIZE (256)
+#define MAX_COMPARE_SIZE (256 + 64)
class compare256: public benchmark::Fixture {
private:
@@ -23,41 +20,53 @@ private:
uint8_t *str2;
public:
- void SetUp(const ::benchmark::State&) {
- str1 = (uint8_t *)zng_alloc(MAX_COMPARE_SIZE);
- assert(str1 != NULL);
- memset(str1, 'a', MAX_COMPARE_SIZE);
+ void SetUp(::benchmark::State& state) {
+ str1 = (uint8_t *)malloc(MAX_COMPARE_SIZE);
+ str2 = (uint8_t *)malloc(MAX_COMPARE_SIZE);
+ if (str1 == NULL || str2 == NULL) {
+ state.SkipWithError("malloc failed");
+ return;
+ }
- str2 = (uint8_t *)zng_alloc(MAX_COMPARE_SIZE);
- assert(str2 != NULL);
+ memset(str1, 'a', MAX_COMPARE_SIZE);
memset(str2, 'a', MAX_COMPARE_SIZE);
}
+ // Benchmark compare256, with rolling buffer misalignment for consistent results
void Bench(benchmark::State& state, compare256_func compare256) {
+ int misalign = 0;
int32_t match_len = (int32_t)state.range(0) - 1;
uint32_t len = 0;
- str2[match_len] = 0;
for (auto _ : state) {
- len = compare256((const uint8_t *)str1, (const uint8_t *)str2);
+ str2[match_len + misalign] = 0; // Set new match limit
+
+ len = compare256((const uint8_t *)str1 + misalign, (const uint8_t *)str2 + misalign);
+
+ str2[match_len + misalign] = 'a'; // Reset match limit
+
+ if (misalign >= 63)
+ misalign = 0;
+ else
+ misalign++;
}
- str2[match_len] = 'a';
+ // Prevent the result from being optimized away
benchmark::DoNotOptimize(len);
}
void TearDown(const ::benchmark::State&) {
- zng_free(str1);
- zng_free(str2);
+ free(str1);
+ free(str2);
}
};
-#define BENCHMARK_COMPARE256(name, fptr, support_flag) \
+#define BENCHMARK_COMPARE256(name, comparefunc, support_flag) \
BENCHMARK_DEFINE_F(compare256, name)(benchmark::State& state) { \
if (!(support_flag)) { \
state.SkipWithError("CPU does not support " #name); \
} \
- Bench(state, fptr); \
+ Bench(state, comparefunc); \
} \
BENCHMARK_REGISTER_F(compare256, name)->Arg(1)->Arg(10)->Arg(40)->Arg(80)->Arg(100)->Arg(175)->Arg(256);
diff --git a/test/benchmarks/benchmark_compare256_rle.cc b/test/benchmarks/benchmark_compare256_rle.cc
index c7da505117..7e6551dbd7 100644
--- a/test/benchmarks/benchmark_compare256_rle.cc
+++ b/test/benchmarks/benchmark_compare256_rle.cc
@@ -3,17 +3,14 @@
* For conditions of distribution and use, see copyright notice in zlib.h
*/
-#include <stdio.h>
-
#include <benchmark/benchmark.h>
extern "C" {
# include "zbuild.h"
-# include "zutil_p.h"
# include "compare256_rle.h"
}
-#define MAX_COMPARE_SIZE (256)
+#define MAX_COMPARE_SIZE (256 + 64)
class compare256_rle: public benchmark::Fixture {
private:
@@ -21,43 +18,55 @@ private:
uint8_t *str2;
public:
- void SetUp(const ::benchmark::State&) {
- str1 = (uint8_t *)zng_alloc(MAX_COMPARE_SIZE);
- assert(str1 != NULL);
- memset(str1, 'a', MAX_COMPARE_SIZE);
+ void SetUp(::benchmark::State& state) {
+ str1 = (uint8_t *)malloc(MAX_COMPARE_SIZE);
+ str2 = (uint8_t *)malloc(MAX_COMPARE_SIZE);
+ if (str1 == NULL || str2 == NULL) {
+ state.SkipWithError("malloc failed");
+ return;
+ }
- str2 = (uint8_t *)zng_alloc(MAX_COMPARE_SIZE);
- assert(str2 != NULL);
+ memset(str1, 'a', MAX_COMPARE_SIZE);
memset(str2, 'a', MAX_COMPARE_SIZE);
}
+ // Benchmark compare256_rle, with rolling buffer misalignment for consistent results
void Bench(benchmark::State& state, compare256_rle_func compare256_rle) {
+ int misalign = 0;
int32_t match_len = (int32_t)state.range(0) - 1;
uint32_t len = 0;
- str2[match_len] = 0;
for (auto _ : state) {
- len = compare256_rle((const uint8_t *)str1, (const uint8_t *)str2);
+ str2[match_len + misalign] = 0; // Set new match limit
+
+ len = compare256_rle((const uint8_t *)str1 + misalign, (const uint8_t *)str2 + misalign);
+
+ str2[match_len + misalign] = 'a'; // Reset match limit
+
+ if (misalign >= 63)
+ misalign = 0;
+ else
+ misalign++;
}
- str2[match_len] = 'a';
+ // Prevent the result from being optimized away
benchmark::DoNotOptimize(len);
}
void TearDown(const ::benchmark::State&) {
- zng_free(str1);
- zng_free(str2);
+ free(str1);
+ free(str2);
}
};
-#define BENCHMARK_COMPARE256_RLE(name, fptr, support_flag) \
+#define BENCHMARK_COMPARE256_RLE(name, comparefunc, support_flag) \
BENCHMARK_DEFINE_F(compare256_rle, name)(benchmark::State& state) { \
if (!(support_flag)) { \
state.SkipWithError("CPU does not support " #name); \
} \
- Bench(state, fptr); \
+ Bench(state, comparefunc); \
} \
- BENCHMARK_REGISTER_F(compare256_rle, name)->Range(1, MAX_COMPARE_SIZE);
+ BENCHMARK_REGISTER_F(compare256_rle, name)->Arg(1)->Arg(10)->Arg(40)->Arg(80)->Arg(100)->Arg(175)->Arg(256);;
BENCHMARK_COMPARE256_RLE(8, compare256_rle_8, 1);
BENCHMARK_COMPARE256_RLE(16, compare256_rle_16, 1);