summaryrefslogtreecommitdiff
path: root/neozip/test/benchmarks/benchmark_png_encode.cc
diff options
context:
space:
mode:
authorMehmet Samet Duman <yongdohyun@projecttick.org>2026-04-02 19:56:09 +0300
committerMehmet Samet Duman <yongdohyun@projecttick.org>2026-04-02 19:56:09 +0300
commit7fb132859fda54aa96bc9dd46d302b343eeb5a02 (patch)
treeb43ae77d7451fb470a260c03349a1caf2846c5e5 /neozip/test/benchmarks/benchmark_png_encode.cc
parentb1e34e861b5d732afe828d58aad2c638135061fd (diff)
parentc2712b8a345191f6ed79558c089777df94590087 (diff)
downloadProject-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_png_encode.cc')
-rw-r--r--neozip/test/benchmarks/benchmark_png_encode.cc54
1 files changed, 54 insertions, 0 deletions
diff --git a/neozip/test/benchmarks/benchmark_png_encode.cc b/neozip/test/benchmarks/benchmark_png_encode.cc
new file mode 100644
index 0000000000..d5e25cbc9d
--- /dev/null
+++ b/neozip/test/benchmarks/benchmark_png_encode.cc
@@ -0,0 +1,54 @@
+#include <stdio.h>
+#include <assert.h>
+#include <benchmark/benchmark.h>
+#include "benchmark_png_shared.h"
+
+#define IMWIDTH 1024
+#define IMHEIGHT 1024
+
+class png_encode: public benchmark::Fixture {
+private:
+ png_dat outpng;
+
+ /* Backing this on the heap is a more realistic benchmark */
+ uint8_t *input_img_buf = NULL;
+
+public:
+ /* Let's make the vanilla version have something extremely compressible */
+ virtual void init_img(png_bytep img_bytes, size_t width, size_t height) {
+ init_compressible(img_bytes, width * height);
+ }
+
+ void SetUp(const ::benchmark::State&) {
+ input_img_buf = (uint8_t*)malloc(IMWIDTH * IMHEIGHT * 3);
+ outpng.buf = (uint8_t*)malloc(IMWIDTH * IMHEIGHT * 3);
+ /* Using malloc rather than zng_alloc so that we can call realloc.
+ * IMWIDTH * IMHEIGHT is likely to be more than enough bytes, though,
+ * given that a simple run length encoding already pretty much can
+ * reduce to this */
+ outpng.len = 0;
+ outpng.buf_rem = IMWIDTH * IMHEIGHT * 3;
+ assert(input_img_buf != NULL);
+ assert(outpng.buf != NULL);
+ init_img(input_img_buf, IMWIDTH, IMHEIGHT);
+ }
+
+ /* State in this circumstance will convey the compression level */
+ void Bench(benchmark::State &state) {
+ for (auto _ : state) {
+ encode_png((png_bytep)input_img_buf, &outpng, state.range(0), IMWIDTH, IMHEIGHT);
+ outpng.buf_rem = outpng.len;
+ outpng.len = 0;
+ }
+ }
+
+ void TearDown(const ::benchmark::State &) {
+ free(input_img_buf);
+ free(outpng.buf);
+ }
+};
+
+BENCHMARK_DEFINE_F(png_encode, encode_compressible)(benchmark::State &state) {
+ Bench(state);
+}
+BENCHMARK_REGISTER_F(png_encode, encode_compressible)->DenseRange(0, 9, 1)->Unit(benchmark::kMicrosecond);