|
1 | | -import hashlib |
2 | 1 | import os |
3 | 2 | import random |
4 | 3 |
|
|
12 | 11 | DATA_5B = os.urandom(5) |
13 | 12 | DATA_1KB = os.urandom(1000) |
14 | 13 | DATA_10KB = os.urandom(10000) |
| 14 | +DATA_2MB = os.urandom(2 * 1024 * 1024) |
15 | 15 |
|
16 | 16 |
|
17 | 17 | # ── macro bench: larger inputs where hashing dominates ─────────────── |
@@ -146,3 +146,60 @@ def test_xxh3_64_ctor(): |
146 | 146 | @pytest.mark.benchmark |
147 | 147 | def test_xxh3_128_ctor(): |
148 | 148 | xxhash.xxh3_128(DATA_STR, seed=SEED_64) |
| 149 | + |
| 150 | + |
| 151 | +# ── 2MB throughput: hashing dominates, call overhead negligible ───── |
| 152 | + |
| 153 | + |
| 154 | +@pytest.mark.benchmark |
| 155 | +def test_xxh32_intdigest_2mb(): |
| 156 | + xxhash.xxh32_intdigest(DATA_2MB, seed=SEED_32) |
| 157 | + |
| 158 | + |
| 159 | +@pytest.mark.benchmark |
| 160 | +def test_xxh64_intdigest_2mb(): |
| 161 | + xxhash.xxh64_intdigest(DATA_2MB, seed=SEED_64) |
| 162 | + |
| 163 | + |
| 164 | +@pytest.mark.benchmark |
| 165 | +def test_xxh3_64_intdigest_2mb(): |
| 166 | + xxhash.xxh3_64_intdigest(DATA_2MB, seed=SEED_64) |
| 167 | + |
| 168 | + |
| 169 | +@pytest.mark.benchmark |
| 170 | +def test_xxh3_128_intdigest_2mb(): |
| 171 | + xxhash.xxh3_128_intdigest(DATA_2MB, seed=SEED_64) |
| 172 | + |
| 173 | + |
| 174 | +@pytest.mark.benchmark |
| 175 | +def test_xxh32_hexdigest_2mb(): |
| 176 | + xxhash.xxh32_hexdigest(DATA_2MB, seed=SEED_32) |
| 177 | + |
| 178 | + |
| 179 | +@pytest.mark.benchmark |
| 180 | +def test_xxh3_64_hexdigest_2mb(): |
| 181 | + xxhash.xxh3_64_hexdigest(DATA_2MB, seed=SEED_64) |
| 182 | + |
| 183 | + |
| 184 | +@pytest.mark.benchmark |
| 185 | +def test_xxh32_stream_intdigest_2mb(): |
| 186 | + h = xxhash.xxh32(DATA_2MB, seed=SEED_32) |
| 187 | + h.intdigest() |
| 188 | + |
| 189 | + |
| 190 | +@pytest.mark.benchmark |
| 191 | +def test_xxh64_stream_intdigest_2mb(): |
| 192 | + h = xxhash.xxh64(DATA_2MB, seed=SEED_64) |
| 193 | + h.intdigest() |
| 194 | + |
| 195 | + |
| 196 | +@pytest.mark.benchmark |
| 197 | +def test_xxh3_64_stream_intdigest_2mb(): |
| 198 | + h = xxhash.xxh3_64(DATA_2MB, seed=SEED_64) |
| 199 | + h.intdigest() |
| 200 | + |
| 201 | + |
| 202 | +@pytest.mark.benchmark |
| 203 | +def test_xxh3_128_stream_intdigest_2mb(): |
| 204 | + h = xxhash.xxh3_128(DATA_2MB, seed=SEED_64) |
| 205 | + h.intdigest() |
0 commit comments