Files
cpp-project-template/third_party/zlib-ng/test/benchmarks/benchmark_png_encode.cc
tqcq 68b2e7f763
Some checks failed
sm-rpc / build (Debug, arm-linux-gnueabihf) (push) Successful in 1m34s
sm-rpc / build (Debug, aarch64-linux-gnu) (push) Successful in 2m46s
sm-rpc / build (Debug, host.gcc) (push) Failing after 1m28s
sm-rpc / build (Release, aarch64-linux-gnu) (push) Successful in 2m14s
sm-rpc / build (Release, arm-linux-gnueabihf) (push) Successful in 2m8s
sm-rpc / build (Debug, mipsel-linux-gnu) (push) Successful in 5m35s
sm-rpc / build (Release, host.gcc) (push) Failing after 1m55s
sm-rpc / build (Release, mipsel-linux-gnu) (push) Successful in 7m21s
fix: breakpad use miniz
2025-08-25 15:24:22 +08:00

55 lines
1.8 KiB
C++

#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& 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 &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);