diff options
| author | Mehmet Samet Duman <yongdohyun@projecttick.org> | 2026-04-02 19:56:09 +0300 |
|---|---|---|
| committer | Mehmet Samet Duman <yongdohyun@projecttick.org> | 2026-04-02 19:56:09 +0300 |
| commit | 7fb132859fda54aa96bc9dd46d302b343eeb5a02 (patch) | |
| tree | b43ae77d7451fb470a260c03349a1caf2846c5e5 /neozip/test/benchmarks/benchmark_compress.cc | |
| parent | b1e34e861b5d732afe828d58aad2c638135061fd (diff) | |
| parent | c2712b8a345191f6ed79558c089777df94590087 (diff) | |
| download | Project-Tick-7fb132859fda54aa96bc9dd46d302b343eeb5a02.tar.gz Project-Tick-7fb132859fda54aa96bc9dd46d302b343eeb5a02.zip | |
Add 'neozip/' from commit 'c2712b8a345191f6ed79558c089777df94590087'
git-subtree-dir: neozip
git-subtree-mainline: b1e34e861b5d732afe828d58aad2c638135061fd
git-subtree-split: c2712b8a345191f6ed79558c089777df94590087
Diffstat (limited to 'neozip/test/benchmarks/benchmark_compress.cc')
| -rw-r--r-- | neozip/test/benchmarks/benchmark_compress.cc | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/neozip/test/benchmarks/benchmark_compress.cc b/neozip/test/benchmarks/benchmark_compress.cc new file mode 100644 index 0000000000..df042f7153 --- /dev/null +++ b/neozip/test/benchmarks/benchmark_compress.cc @@ -0,0 +1,75 @@ +/* benchmark_compress.cc -- benchmark compress() + * Copyright (C) 2024-2025 Hans Kristian Rosbach + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +#include <stdio.h> +#include <assert.h> +#include <benchmark/benchmark.h> + +extern "C" { +# include "zbuild.h" +# include "zutil_p.h" +# if defined(ZLIB_COMPAT) +# include "zlib.h" +# else +# include "zlib-ng.h" +# endif +# include "test/compressible_data_p.h" +} + +#define MAX_SIZE (64 * 1024) + +class compress_bench: public benchmark::Fixture { +private: + uint8_t *inbuff; + uint8_t *outbuff; + +public: + void SetUp(::benchmark::State& state) { + outbuff = (uint8_t *)malloc(MAX_SIZE + 16); + if (outbuff == NULL) { + state.SkipWithError("malloc failed"); + return; + } + + // Initialize input buffer with highly compressible data, interspersed + // with small amounts of random data and 3-byte matches. + inbuff = gen_compressible_data(MAX_SIZE); + if (inbuff == NULL) { + free(outbuff); + outbuff = NULL; + state.SkipWithError("gen_compressible_data() failed"); + return; + } + } + + void Bench(benchmark::State& state) { + int err = 0; + + for (auto _ : state) { + z_uintmax_t compressed_size = MAX_SIZE + 16; + err = PREFIX(compress)(outbuff, &compressed_size, inbuff, (size_t)state.range(0)); + if (err != Z_OK) { + fprintf(stderr, "compress() failed with error %d\n", err); + abort(); + } + + // Prevent the result from being optimized away + benchmark::DoNotOptimize(err); + } + } + + void TearDown(const ::benchmark::State&) { + free(inbuff); + free(outbuff); + } +}; + +#define BENCHMARK_COMPRESS(name) \ + BENCHMARK_DEFINE_F(compress_bench, name)(benchmark::State& state) { \ + Bench(state); \ + } \ + BENCHMARK_REGISTER_F(compress_bench, name)->Arg(1)->Arg(16)->Arg(48)->Arg(256)->Arg(1<<10)->Arg(4<<10)->Arg(16<<10)->Arg(64<<10); + +BENCHMARK_COMPRESS(compress_bench); |
