1
0
mirror of https://github.com/lz4/lz4.git synced 2026-10-24 01:48:57 +03:00

88 Commits

Author SHA1 Message Date
Yann Collet
bf2b488182 bench: decode-only mode shares the whole result buffer
`lz4 -b -d` reserved 255x each frame's compressed size in the result
buffer, but capped that buffer at LZ4_MAX_INPUT_SIZE. With multiple
large files, later frames pointed past the buffer : 4 files of 4 MB
crash. The decode loop also recomputed each capacity with an INT_MAX
cap instead, so a frame decoding to more than LZ4_MAX_INPUT_SIZE wrote
out of bounds.

Decode-only output is not checked, so all frames now decode at the
start of the result buffer, each with its whole capacity. The capacity
is computed once, when the block table is laid out, and reused by the
decode loop.

Bug since v1.9.4. Based on #1770 by @arshsmith1
2026-10-19 20:46:34 -07:00
Yann Collet
c2ecde85b9 bench: fix compressed buffer size with small blocks
BMK_benchMem() sized the compressed buffer with a margin of 1024 bytes
per block, computed as `maxNbBlocks * 1024` in 32-bit unsigned
arithmetic. With 4M blocks or more (e.g. `-B32` on a 128 MiB input),
the product wrapped around, and the buffer could be smaller than the
LZ4_compressBound() of all blocks, making the benchmark write past its end.

LZ4_compressBound() adds exactly 16 bytes per block, so the margin is
now `maxNbBlocks * 16`, computed in size_t.
2026-10-19 16:28:38 -07:00
Yann Collet
97c68c2cd9 cap acceleration at LZ4_ACCELERATION_MAX, now defined in lz4.h
Follow-up to "lz4frame: avoid signed overflow", per the #1824 review:
saturate at LZ4_ACCELERATION_MAX rather than INT_MAX,
since higher values make no difference.

LZ4_ACCELERATION_DEFAULT and LZ4_ACCELERATION_MAX move from lz4.c
to the LZ4_STATIC_LINKING_ONLY section of lz4.h, which lz4.c, lz4frame.c,
bench.c and frametest.c already include, so their values derive from it.
The LZ4_compress_fast() documentation already referred to both constants.

bench.c computed the acceleration the same way (-cLevel + 1),
so `lz4 -b --fast=2147483647` hit the same signed overflow:
apply the same cap there.

test-lz4-basic.sh: --fast=2147483647 must produce the same frame
as --fast=65536 (fails on dev, where acceleration wraps to the default),
and its benchmark runs (caught by the UBSan CI job before this fix).

lz4.1: --fast values above 65536 make no difference.
2026-10-18 11:20:02 -07:00
Yann Collet
c57dfafe27 bench: align display when speed > 10000 MB/s
as cpus get faster, it's now possible for some of them to reach speeds > 10000 MB/s on single core.
Ensure that the display remains properly aligned in this case.
2026-01-24 22:40:20 -08:00
Yann Collet
2719f42eb5 removed year from header (#1605)
as it's a burden to maintain, and wasn't consistently updated.

Now rely on git dating.
2025-04-27 10:55:25 -08:00
Yann Collet
21837b9621 fixed traces 2024-07-19 18:19:07 -07:00
Yann Collet
f458b2b1a5 LZ4_loadDictHC is compatible with LZ4MID level 2
But the state must have its compression level set _before_ loading the dictionary.
2024-07-17 23:01:08 -07:00
Yann Collet
1a5b83b8c4 benchmark results are displayed to stdout
instead of stderr
2024-04-03 22:49:11 -07:00
Yann Collet
10921d86c8 another minor compression improvement for level 2
using catch back
2024-02-07 00:14:12 -08:00
Yann Collet
73dd539a6e minor optimizations 2024-01-28 01:10:15 -08:00
Yann Collet
823d37f730 bench.c does not longer need datagen
datagen transferred to tests/
2024-01-28 00:56:56 -08:00
Yann Collet
f9eb26664e added a lorem ipsum generator
and use it as primary syntehtic source for the internal benchmark program
2024-01-28 00:35:59 -08:00
Yann Collet
ef6442b504 fix minor static analyzer warnings
regarding uninitialized variables
2023-12-28 22:06:48 -08:00
Yann Collet
553962bd39 better time measurement and reportin 2023-12-27 23:32:37 -08:00
Yann Collet
dc474bd84a fix minor conversion warnings
appearing with clang-17
2023-12-19 23:11:29 -08:00
Yann Collet
8a0d78f97f minor: fixed incorrectly position comma (,)
in bench results.
2023-09-06 11:35:10 -07:00
Dimitri Papadopoulos
bdfe4c0c98 Enclose by a do-while loop to avoid possible if/else logic defects 2023-06-25 17:43:51 +02:00
Yann Collet
251e04a9c1 added test able to catch bug #1167
also : errors during benchmark mode return an error code.
2022-09-15 16:48:28 -07:00
Yann Collet
ec0d3e6ec9 fix benchmark more using Dictionary
benchmark dictionary mode, implemented in #808, is incorrect.
It would desynchronize compression and decompression as soon as 2+ files are dictionary compressed.

Also : slightly improved traces system, to also include __LINE__ number
2022-09-15 16:25:00 -07:00
Dominique Pelle
3347485307 fix: various typos 2022-07-31 17:47:00 +02:00
Yann Collet
9978bb90cf fixed minor pedantic warning 2022-07-29 23:31:08 +02:00
Yann Collet
f01b7b5209 can select validation of CRC during benchmark
on command line, using existing long command --no-frame-crc.
Note : it's effectively more than that, since _all_ checksums are disabled.
2022-07-29 22:13:38 +02:00
Yann Collet
4f4d09a0d1 implement decoder-only benchmark mode
requires an LZ4 Frame as input
2022-07-29 19:22:59 +02:00
Yann Collet
cd96e3e7a5 minor refactor
to prepare bench.c for multiple decoding functions.
2022-07-29 15:24:50 +02:00
Yann Collet
df4bb410e3 updated documentation of bench unit 2022-07-29 14:51:52 +02:00
Yann Collet
598eafde2d minor : fix conversion warnings 2022-07-29 14:34:53 +02:00
Yann Collet
87a80acbe7 updated license & header dates 2020-11-25 14:45:14 -08:00
Reto Koradi
cc91777c98 Make benchmark compatible with dictionary compression
Support the -D command line option for running benchmarks. The
benchmark code was slightly restructured to factor out the calls
that need to be different for each benchmark scenario. Since there
are now 4 scenarios (all combinations of fast/HC and with/without
dictionary), the logic was getting somewhat convoluted otherwise.

This was done by extending the compressionParameters struct that
previously contained just a single function pointer. It now
contains 4 function pointers for init/reset/compress/cleanup,
with the related state. The functions get a pointer to the
structure as their first argument (inspired by C++), so that they
can access the state values in the struct.
2019-11-05 23:38:00 -08:00
Yann Collet
4f6de46f60 fix several minor static analyzer warnings 2019-04-18 12:05:50 -07:00
Yann Collet
2e4847c2d5 fixed #560
it was a fairly complex scenario,
involving source files > 64K
and some extraordinary conditions related to specific layout of ranges of zeroes.
and only on level 9.
2018-09-04 18:21:40 -07:00
Jennifer Liu
e778db373b Fixed bugs about incorrect acceleration calculation and benchmarking negative compresion level 2018-06-27 13:36:38 -07:00
Jennifer Liu
9ee5183d9b Fixed code based on comments from pull request 2018-06-26 17:31:15 -07:00
Jennifer Liu
9f8fd09852 delete commented out code in bench.c 2018-06-26 10:49:39 -07:00
Jennifer Liu
536b79afd9 Added --fast command to cli 2018-06-25 17:46:39 -07:00
Yann Collet
1faa7e2698 bench: introduced hidden command -S
to benchmark multiple files with separate results
2018-03-19 17:19:25 -07:00
Yann Collet
179670f32f use TIMELOOP_NANOSEC,
as suggested by @terrelln
2018-02-20 15:26:59 -08:00
Yann Collet
34c1634d4b fixed minor conversion warning 2018-02-20 14:13:13 -08:00
Yann Collet
ae3dededed ensure bench speed measurement is more accurate for small inputs
Previous method would produce too many time() invocations,
becoming a significant fraction of workload measured.

The new strategy is to use time() only once per batch,
and dynamically resize batch size so that each round lasts approximately 1 second.

This only matters for small inputs.
Measurement for large files (such as silesia.tar) are much less impacted
(though decoding speed is so fast that even medium-size files will notice an improvement).
2018-02-20 13:09:13 -08:00
Yann Collet
1a233c5f0f update bench.c to use less time invocations
translating into more accurate speed measurements for small sources
2018-02-20 11:37:19 -08:00
Nick Terrell
74d8688bc8 [bench] Use higher resolution timer on POSIX
The timer used was only accurate up to 0.01 seconds. This timer is accurate up to 1 ns.
It is a monotonic timer that measures the real time difference, not on CPU time.

Copied the benchmark code from 6ab4d5e904
2017-10-17 13:55:35 -07:00
Yann Collet
a30cba08f4 fixed a bunch of -Wcomma warnings
reported by @rvandermeulen (#398)
2017-09-10 14:32:38 -07:00
Yann Collet
00418f7611 bench : made decompression speed evaluation same time as compression
minor : slightly modified an example do avoid disabling a gcc warning through #pragma
2017-09-07 12:12:36 -07:00
Przemyslaw Skibinski
cb1671955a bench.c: respect LZ4_MAX_INPUT_SIZE limit 2017-03-10 20:49:25 +01:00
Przemyslaw Skibinski
40ad1e85d4 upgraded util.h 2017-02-15 17:16:15 +01:00
Chocobo1
db6f733ecc Use logical or instead of bitwise or 2017-01-13 00:43:25 +08:00
Yann Collet
b41f9bb132 Merge pull request #292 from inikep/dev
improved POSIX
2016-12-22 11:58:29 +01:00
Yann Collet
52cac9a973 updated a few macros names 2016-12-22 11:41:05 +01:00
Przemyslaw Skibinski
f084b65383 test Large File support for Mac OS-X in 32-bits mode 2016-12-21 17:13:38 +01:00
Przemyslaw Skibinski
2cfef13952 executables use platform.h 2016-12-20 18:05:43 +01:00
Przemyslaw Skibinski
7b6a9d8638 Merge remote-tracking branch 'refs/remotes/lz4/dev' into dev 2016-11-16 09:01:45 +01:00