]> git.ipfire.org Git - thirdparty/libarchive.git/commit
Avoid millions of rand() calls() when running tests 1438/head
authorAlex Richardson <Alexander.Richardson@cl.cam.ac.uk>
Thu, 17 Sep 2020 17:28:17 +0000 (18:28 +0100)
committerAlex Richardson <Alexander.Richardson@cl.cam.ac.uk>
Sat, 15 Jan 2022 13:47:21 +0000 (13:47 +0000)
commit10a9214ac65e171f08589ef0ec94ffcbccbfcc49
tree69acfc0e0ab9faaa856f692a49fc0390d8c835dc
parentb9675888c288fb8b293a69783712bbc2a4573773
Avoid millions of rand() calls() when running tests

Many tests use a loop calling rand() to fill buffers with test data. As
these calls cannot be inlined, this adds up to noticeable overhead:
For example, running on QEMU RISC-V the test_write_format_7zip_large_copy
test took ~22 seconds before and with this change it's ~17 seconds.
This change uses a simpler xorshift64 random number generator that can be
inlined into the loop filling the data buffer. By default the seed for this
RNG is rand(), but it can be overwritten by setting the TEST_RANDOM_SEED
environment variable.

For a native build the difference is much less noticeable, but it's still
measurable: test_write_format_7zip_large_copy takes 314.9 ms ± 3.9 ms
before and 227.8 ms ± 5.8 ms after (i.e. 38% faster for that test).
libarchive/test/test_read_data_large.c
libarchive/test/test_read_extract.c
libarchive/test/test_read_large.c
libarchive/test/test_read_pax_truncated.c
libarchive/test/test_read_truncated.c
libarchive/test/test_read_truncated_filter.c
libarchive/test/test_write_format_7zip_large.c
test_utils/test_utils.c
test_utils/test_utils.h