aboutsummaryrefslogtreecommitdiff
path: root/modules/benchmark
diff options
context:
space:
mode:
authorBurt P <pburt0@gmail.com>2018-10-26 21:52:37 -0500
committerLeandro A. F. Pereira <leandro@hardinfo.org>2019-06-29 10:52:53 -0700
commit6a8e19a14305079b03e45eeb0580a45104f300dd (patch)
tree873cd25b12cc497355659a1427bd015d7b5b9d68 /modules/benchmark
parent46954ed789c04ee4ff8c92892f1bfc6883696628 (diff)
benchmark/zlib: new version of zlib benchmark
The new version uses a fixed time (7s) and the results are much more consistent than the previous version. A couple results for the new version, one "low" and one "high", replace the old results, which were quite strange. Signed-off-by: Burt P <pburt0@gmail.com>
Diffstat (limited to 'modules/benchmark')
-rw-r--r--modules/benchmark/zlib.c77
1 files changed, 48 insertions, 29 deletions
diff --git a/modules/benchmark/zlib.c b/modules/benchmark/zlib.c
index 894d8e18..5d7b4d4f 100644
--- a/modules/benchmark/zlib.c
+++ b/modules/benchmark/zlib.c
@@ -22,15 +22,12 @@
#include "benchmark.h"
-/* must be less than or equal to
- * file size of ( params.path_data + "benchmark.data" ) */
-#define BENCH_DATA_SIZE 65536
+/* zip/unzip 256KB blocks for 7 seconds
+ * result is number of full completions / 100 */
+#define BENCH_DATA_SIZE 262144
+#define CRUNCH_TIME 7
-#define BENCH_EVENTS 50000
-#define BENCH_WTF_NUMBER 840205128
-
-static gpointer zlib_for(unsigned int start, unsigned int end, void *data, gint thread_number)
-{
+static gpointer zlib_for(void *in_data, gint thread_number) {
char *compressed;
uLong bound = compressBound(BENCH_DATA_SIZE);
unsigned int i;
@@ -39,42 +36,64 @@ static gpointer zlib_for(unsigned int start, unsigned int end, void *data, gint
if (!compressed)
return NULL;
- for (i = start; i <= end; i++) {
- char uncompressed[BENCH_DATA_SIZE];
- uLong compressedBound = bound;
- uLong destBound = sizeof(uncompressed);
+ char uncompressed[BENCH_DATA_SIZE];
+ uLong compressedBound = bound;
+ uLong destBound = sizeof(uncompressed);
- compress(compressed, &compressedBound, data, BENCH_DATA_SIZE);
- uncompress(uncompressed, &destBound, compressed, compressedBound);
- }
+ compress(compressed, &compressedBound, in_data, BENCH_DATA_SIZE);
+ uncompress(uncompressed, &destBound, compressed, compressedBound);
free(compressed);
return NULL;
}
+static gchar *get_test_data(gsize min_size) {
+ gchar *bdata_path, *data;
+ gsize data_size;
+
+ gchar *exp_data, *p;
+ gsize sz;
+
+ bdata_path = g_build_filename(params.path_data, "benchmark.data", NULL);
+ if (!g_file_get_contents(bdata_path, &data, &data_size, NULL)) {
+ g_free(bdata_path);
+ return NULL;
+ }
+
+ if (data_size < min_size) {
+ DEBUG("expanding %lu bytes of test data to %lu bytes", data_size, min_size);
+ exp_data = g_malloc(min_size + 1);
+ memcpy(exp_data, data, data_size);
+ p = exp_data + data_size;
+ sz = data_size;
+ while (sz < (min_size - data_size) ) {
+ memcpy(p, data, data_size);
+ p += data_size;
+ sz += data_size;
+ }
+ strncpy(p, data, min_size - sz);
+ g_free(data);
+ data = exp_data;
+ }
+ g_free(bdata_path);
+ return data;
+}
+
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 *data = get_test_data(BENCH_DATA_SIZE);
+ if (!data)
return;
- }
shell_view_set_enabled(FALSE);
shell_status_update("Running Zlib benchmark...");
- r = benchmark_parallel_for(0, 0, BENCH_EVENTS, zlib_for, tmpsrc);
-
- g_free(bdata_path);
- g_free(tmpsrc);
-
- //TODO: explain in code comments!
- gdouble marks = ((double)BENCH_EVENTS * (double)BENCH_DATA_SIZE) / (r.elapsed_time * (double)BENCH_WTF_NUMBER);
- r.result = marks;
+ r = benchmark_crunch_for(CRUNCH_TIME, 0, zlib_for, data);
+ r.result /= 100;
bench_results[BENCHMARK_ZLIB] = r;
+
+ g_free(data);
}