test-compress-benchmark.c revision fd53fee04b1f1c1ca1e30e8d470d7416900a35dc
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi This file is part of systemd
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi Copyright 2014 Zbigniew Jędrzejewski-Szmek
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi systemd is free software; you can redistribute it and/or modify it
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi under the terms of the GNU Lesser General Public License as published by
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi the Free Software Foundation; either version 2.1 of the License, or
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi (at your option) any later version.
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi systemd is distributed in the hope that it will be useful, but
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi WITHOUT ANY WARRANTY; without even the implied warranty of
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi Lesser General Public License for more details.
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi You should have received a copy of the GNU Lesser General Public License
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi along with systemd; If not, see <http://www.gnu.org/licenses/>.
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchitypedef int (compress_t)(const void *src, uint64_t src_size, void *dst, uint64_t *dst_size);
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchitypedef int (decompress_t)(const void *src, uint64_t src_size,
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi void **dst, uint64_t *dst_alloc_size, uint64_t* dst_size, uint64_t dst_max);
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi for (i = 0; i < count; i++)
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchistatic void test_compress_decompress(const char* label,
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi compress_t compress, decompress_t decompress) {
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi size_t skipped = 0, compressed = 0, total = 0;
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi for (size_t i = 1; i <= MAX_SIZE; i += (i < 2048 ? 1 : 217)) {
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi /* assume compresion must be succesful except for small inputs */
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi assert(r == 0 || (i < 2048 && r == -ENOBUFS));
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi /* check for overwrites */
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi if (r != 0) {
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi log_error("%s \"compressed\" %zu -> %zu", label, i, j);
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi r = decompress(buf, j, &buf2, &buf2_allocated, &k, 0);
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi log_info("%s: compressed & decompressed %zu bytes in %.2fs (%.2fMiB/s), "
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi "mean compresion %.2f%%, skipped %zu bytes",
d14abf155341d55053c76eeec58b787a456b753bRobert Mustacchi test_compress_decompress("XZ", compress_blob_xz, decompress_blob_xz);