aboutsummaryrefslogtreecommitdiff
path: root/modules/benchmark/zlib.c
diff options
context:
space:
mode:
authorLucas de Castro Borges <lucas@gnuabordo.com.br>2024-04-22 00:35:53 -0300
committerLucas de Castro Borges <lucas@gnuabordo.com.br>2024-04-22 00:35:53 -0300
commit5f01c706267c595de92406a32e7f31ef5056c2d0 (patch)
treed1e74ef54efc41ada622900fe3e2a50dee44a237 /modules/benchmark/zlib.c
parent09fcc751ef158898c315ebc9299a0fa3a722d914 (diff)
New upstream version 2.0.3preupstream/2.0.3pre
Diffstat (limited to 'modules/benchmark/zlib.c')
-rw-r--r--modules/benchmark/zlib.c63
1 files changed, 39 insertions, 24 deletions
diff --git a/modules/benchmark/zlib.c b/modules/benchmark/zlib.c
index 2ded59a4..2045969f 100644
--- a/modules/benchmark/zlib.c
+++ b/modules/benchmark/zlib.c
@@ -1,10 +1,10 @@
/*
* HardInfo - Displays System Information
- * Copyright (C) 2017 Leandro A. F. Pereira <leandro@hardinfo.org>
+ * Copyright (C) 2017 L. A. F. Pereira <l@tia.mat.br>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 2.
+ * the Free Software Foundation, version 2 or later.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -22,23 +22,39 @@
#include "benchmark.h"
-static gpointer zlib_for(unsigned int start, unsigned int end, void *data, gint thread_number)
-{
+/* zip/unzip 256KB blocks for 7 seconds
+ * result is number of full completions / 100 */
+
+/* if anything changes in this block, increment revision */
+#define BENCH_REVISION 3
+#define BENCH_DATA_SIZE 262144
+#define BENCH_DATA_MD5 "3753b649c4fa9ea4576fc8f89a773de2"
+#define CRUNCH_TIME 7
+#define VERIFY_RESULT 1
+
+static unsigned int zlib_errors = 0;
+
+static gpointer zlib_for(void *in_data, gint thread_number) {
char *compressed;
- uLong bound = compressBound(bound);
+ uLong bound = compressBound(BENCH_DATA_SIZE);
unsigned int i;
compressed = malloc(bound);
if (!compressed)
return NULL;
- for (i = start; i <= end; i++) {
- char uncompressed[65536];
- uLong compressedBound = bound;
- uLong destBound = sizeof(uncompressed);
+ char uncompressed[BENCH_DATA_SIZE];
+ uLong compressedBound = bound;
+ uLong destBound = sizeof(uncompressed);
- compress(compressed, &compressedBound, data, 65536);
- uncompress(uncompressed, &destBound, compressed, compressedBound);
+ compress(compressed, &compressedBound, in_data, BENCH_DATA_SIZE);
+ uncompress(uncompressed, &destBound, compressed, compressedBound);
+ if (VERIFY_RESULT) {
+ int cr = memcmp(in_data, uncompressed, BENCH_DATA_SIZE);
+ if (!!cr) {
+ zlib_errors++;
+ bench_msg("zlib error: uncompressed != original");
+ }
}
free(compressed);
@@ -50,24 +66,23 @@ void
benchmark_zlib(void)
{
bench_value r = EMPTY_BENCH_VALUE;
- gchar *tmpsrc, *bdata_path;
-
- bdata_path = g_build_filename(params.path_data, "benchmark.data", NULL);
- if (!g_file_get_contents(bdata_path, &tmpsrc, NULL, NULL)) {
- g_free(bdata_path);
+ gchar *test_data = get_test_data(BENCH_DATA_SIZE);
+ if (!test_data)
return;
- }
shell_view_set_enabled(FALSE);
shell_status_update("Running Zlib benchmark...");
- r = benchmark_parallel_for(0, 0, 50000, zlib_for, tmpsrc);
+ gchar *d = md5_digest_str(test_data, BENCH_DATA_SIZE);
+ if (!SEQ(d, BENCH_DATA_MD5))
+ bench_msg("test data has different md5sum: expected %s, actual %s", BENCH_DATA_MD5, d);
- g_free(bdata_path);
- g_free(tmpsrc);
-
- //TODO: explain in code comments
- gdouble marks = (50000. * 65536.) / (r.elapsed_time * 840205128.);
- r.result = marks;
+ r = benchmark_crunch_for(CRUNCH_TIME, 0, zlib_for, test_data);
+ r.result /= 100;
+ r.revision = BENCH_REVISION;
+ snprintf(r.extra, 255, "zlib %s (built against: %s), d:%s, e:%d", zlib_version, ZLIB_VERSION, d, zlib_errors);
bench_results[BENCHMARK_ZLIB] = r;
+
+ g_free(test_data);
+ g_free(d);
}