From: Nathan Moinvaziri Date: Sat, 27 Jun 2026 20:29:47 +0000 (-0700) Subject: Add DNA data type to benchmark data generators X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f04685cb6c8b3af7699252d69b4d9965e9fef74a;p=thirdparty%2Fzlib-ng.git Add DNA data type to benchmark data generators Add a 4-symbol (DNA base) alphabet generator. With only four symbols nearly every 3-byte prefix collides, producing very long hash chains while matches stay short, which stresses the longest_match short-match path that the existing generators do not isolate. Register it for the deflate and inflate benchmark variants. Assisted-By: Claude Opus 4.8 --- diff --git a/test/benchmarks/benchmark_deflate.cc b/test/benchmarks/benchmark_deflate.cc index ead6b0764..408ed101f 100644 --- a/test/benchmarks/benchmark_deflate.cc +++ b/test/benchmarks/benchmark_deflate.cc @@ -133,6 +133,7 @@ public: #define DEFLATE_ALL_DATA(variant, wbits, strategy, args_macro) \ DEFLATE_VARIANT(variant, text, wbits, strategy, TEST_DATA_TEXT, args_macro); \ DEFLATE_VARIANT(variant, short_match, wbits, strategy, TEST_DATA_SHORT_MATCH, args_macro); \ + DEFLATE_VARIANT(variant, dna, wbits, strategy, TEST_DATA_DNA, args_macro); \ DEFLATE_VARIANT(variant, random, wbits, strategy, TEST_DATA_RANDOM, args_macro); \ DEFLATE_VARIANT(variant, realistic_rgb, wbits, strategy, TEST_DATA_REALISTIC_RGB, args_macro); \ DEFLATE_VARIANT(variant, striped_rgb, wbits, strategy, TEST_DATA_STRIPED_RGB, args_macro) diff --git a/test/benchmarks/benchmark_inflate.cc b/test/benchmarks/benchmark_inflate.cc index e254e507f..98bc394a1 100644 --- a/test/benchmarks/benchmark_inflate.cc +++ b/test/benchmarks/benchmark_inflate.cc @@ -165,6 +165,7 @@ public: INFLATE_VARIANT(text, TEST_DATA_TEXT); INFLATE_VARIANT(short_match, TEST_DATA_SHORT_MATCH); +INFLATE_VARIANT(dna, TEST_DATA_DNA); INFLATE_VARIANT(random, TEST_DATA_RANDOM); INFLATE_VARIANT(realistic_rgb, TEST_DATA_REALISTIC_RGB); INFLATE_VARIANT(striped_rgb, TEST_DATA_STRIPED_RGB); diff --git a/test/test_data_p.h b/test/test_data_p.h index f63e3139f..17691c5a4 100644 --- a/test/test_data_p.h +++ b/test/test_data_p.h @@ -131,6 +131,22 @@ static inline uint8_t *gen_short_match_data(size_t bufsize) { return buf; } +/* Random bytes over a 4-symbol (DNA base) alphabet. Nearly every 3-byte prefix + collides, so hash chains grow very long while matches stay short. Stresses the + longest_match short-match path with deep chain walks. */ +static inline uint8_t *gen_dna_data(size_t bufsize) { + static const uint8_t bases[4] = { 'A', 'C', 'G', 'T' }; + uint8_t *buf = (uint8_t *)malloc(bufsize); + if (buf == NULL) + return NULL; + uint32_t rng = 0x01234567; + for (size_t i = 0; i < bufsize; i++) { + rng = rng * 1103515245u + 12345u; + buf[i] = bases[(rng >> 24) & 3]; + } + return buf; +} + static inline uint8_t clamp_uint8_t(int v) { return (uint8_t)(v < 0 ? 0 : (v > 0xFF ? 0xFF : v)); } @@ -218,6 +234,7 @@ static inline uint8_t *gen_striped_rgb_data(size_t bufsize) { enum test_data_type { TEST_DATA_TEXT = 0, /* mixed literals + short/medium matches */ TEST_DATA_SHORT_MATCH, /* many short back-references */ + TEST_DATA_DNA, /* 4-symbol alphabet, dense chains + short matches */ TEST_DATA_RANDOM, /* incompressible, deflate uses stored blocks */ TEST_DATA_REALISTIC_RGB, /* RGB photo, short matches at dist=3 */ TEST_DATA_STRIPED_RGB, /* solid R/G/B stripes, long dist=3 matches */ @@ -227,6 +244,7 @@ static inline uint8_t *gen_test_data(enum test_data_type data_type, size_t bufsi switch (data_type) { case TEST_DATA_TEXT: return gen_text_data(bufsize); case TEST_DATA_SHORT_MATCH: return gen_short_match_data(bufsize); + case TEST_DATA_DNA: return gen_dna_data(bufsize); case TEST_DATA_RANDOM: return gen_random_data(bufsize); case TEST_DATA_REALISTIC_RGB: return gen_realistic_rgb_data(bufsize); case TEST_DATA_STRIPED_RGB: return gen_striped_rgb_data(bufsize);