]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Add literals data type to benchmark data generators
authorNathan Moin Vaziri <nathan@nathanm.com>
Tue, 7 Jul 2026 02:12:48 +0000 (19:12 -0700)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Wed, 15 Jul 2026 10:53:24 +0000 (12:53 +0200)
High-entropy bytes (~6.5 bits/byte) that deflate encodes as Huffman-coded
blocks with almost no matches, filling the gap between text (skewed codes,
root-table hits) and random (stored blocks, decode loop bypassed).

Assisted-By: Claude Fable 5
test/benchmarks/benchmark_deflate.cc
test/benchmarks/benchmark_inflate.cc
test/test_data_p.h

index 408ed101fcbdee6f5f43a67fc34ddf28269839ac..c201db5de6eebf560f88dd934eaddad33b660cda 100644 (file)
@@ -135,6 +135,7 @@ public:
     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, literals,      wbits, strategy, TEST_DATA_LITERALS,      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)
 
index 98bc394a10db195e4b1e15b6b12749f9ff180b23..7b35101a681453ec4b3ff15dc89988648bc4c128 100644 (file)
@@ -167,5 +167,6 @@ 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(literals,       TEST_DATA_LITERALS);
 INFLATE_VARIANT(realistic_rgb,  TEST_DATA_REALISTIC_RGB);
 INFLATE_VARIANT(striped_rgb,    TEST_DATA_STRIPED_RGB);
index 17691c5a4108314dec1309f98a47f61f7981f90f..1897455767505c9132200143c9b4f4d502690a01 100644 (file)
@@ -165,6 +165,24 @@ static inline uint8_t *gen_random_data(size_t bufsize) {
     return buf;
 }
 
+/* High-entropy literals from mostly the AND of two uniform bytes (~6.5 bits per
+   byte). Deflate emits coded blocks (ratio ~1.1) with few matches. */
+static inline uint8_t *gen_literals_data(size_t bufsize) {
+    uint8_t *buf = (uint8_t *)malloc(bufsize);
+    if (buf == NULL)
+        return NULL;
+    uint32_t rng = 0x600dd1ce;
+    for (size_t i = 0; i < bufsize; i++) {
+        rng = rng * 1103515245u + 12345u;
+        uint8_t a = (uint8_t)(rng >> 24);
+        rng = rng * 1103515245u + 12345u;
+        /* 1/4 of bytes stay fully random to break up 3-byte repeats that
+           deflate would otherwise turn into incidental matches at level 9 */
+        buf[i] = ((rng >> 8) & 3) ? (uint8_t)(a & (rng >> 24)) : a;
+    }
+    return buf;
+}
+
 /* RGB photo-like pixels at a fixed row width: smooth gradients with per-pixel
    noise. Yields short matches at dist=3 (RGB stride) and longer inter-row matches;
    deflate emits scattered literals between them. */
@@ -236,6 +254,7 @@ enum test_data_type {
     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_LITERALS,         /* high-entropy literals, coded blocks, few matches */
     TEST_DATA_REALISTIC_RGB,    /* RGB photo, short matches at dist=3 */
     TEST_DATA_STRIPED_RGB,      /* solid R/G/B stripes, long dist=3 matches */
 };
@@ -246,6 +265,7 @@ static inline uint8_t *gen_test_data(enum test_data_type data_type, size_t bufsi
         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_LITERALS:       return gen_literals_data(bufsize);
         case TEST_DATA_REALISTIC_RGB:  return gen_realistic_rgb_data(bufsize);
         case TEST_DATA_STRIPED_RGB:    return gen_striped_rgb_data(bufsize);
     }