diff options
Diffstat (limited to 'modules/benchmark')
-rw-r--r-- | modules/benchmark/bench_results.c | 19 | ||||
-rw-r--r-- | modules/benchmark/bench_util.c | 58 | ||||
-rw-r--r-- | modules/benchmark/benches.c | 10 | ||||
-rw-r--r-- | modules/benchmark/blowfish2.c | 47 | ||||
-rw-r--r-- | modules/benchmark/cryptohash.c | 36 | ||||
-rw-r--r-- | modules/benchmark/fft.c | 11 | ||||
-rw-r--r-- | modules/benchmark/fib.c | 9 | ||||
-rw-r--r-- | modules/benchmark/nqueens.c | 24 | ||||
-rw-r--r-- | modules/benchmark/raytrace.c | 8 | ||||
-rw-r--r-- | modules/benchmark/zlib.c | 63 |
10 files changed, 186 insertions, 99 deletions
diff --git a/modules/benchmark/bench_results.c b/modules/benchmark/bench_results.c index 3609a5dd..171285d1 100644 --- a/modules/benchmark/bench_results.c +++ b/modules/benchmark/bench_results.c @@ -334,6 +334,15 @@ bench_result *bench_result_benchmarkconf(const char *section, const char *key, c /* old results only give threads */ b->machine->processors = -1; b->machine->cores = -1; + + /* clean the old result's CPU model name + * if it was probably an x86 */ + if (strstr(b->machine->cpu_name, "Intel") + || strstr(b->machine->cpu_name, "AMD") + || strstr(b->machine->cpu_name, "VIA") + || strstr(b->machine->cpu_name, "Cyrix") ) { + nice_name_x86_cpuid_model_string(b->machine->cpu_name); + } } b->machine->cpu_config = cpu_config_retranslate(b->machine->cpu_config, 0, 1); @@ -383,7 +392,8 @@ static char *bench_result_more_info_less(bench_result *b) { /* elapsed */ "%s=%0.4f %s\n" "%s=%s\n" "%s=%s\n" - /* legacy */ "%s=%s\n" + "%s=%s\n" + /* legacy */ "%s%s=%s\n" "[%s]\n" /* board */ "%s=%s\n" /* cpu */ "%s=%s\n" @@ -398,6 +408,8 @@ static char *bench_result_more_info_less(bench_result *b) { _("Elapsed Time"), b->bvalue.elapsed_time, _("seconds"), *bench_str ? _("Revision") : _("#Revision"), bench_str, *b->bvalue.extra ? _("Extra Information") : _("#Extra"), b->bvalue.extra, + *b->bvalue.user_note ? _("User Note") : _("#User Note"), b->bvalue.user_note, + b->legacy ? problem_marker() : "", b->legacy ? _("Note") : "#Note", b->legacy ? _("This result is from an old version of HardInfo. Results might not be comparable to current version. Some details are missing.") : "", _("Machine"), @@ -426,7 +438,8 @@ static char *bench_result_more_info_complete(bench_result *b) { /* result */ "%s=%0.2f\n" /* elapsed */ "%s=%0.4f %s\n" "%s=%s\n" - /* legacy */ "%s=%s\n" + "%s=%s\n" + /* legacy */ "%s%s=%s\n" "[%s]\n" /* board */ "%s=%s\n" /* cpu */ "%s=%s\n" @@ -445,6 +458,8 @@ static char *bench_result_more_info_complete(bench_result *b) { _("Result"), b->bvalue.result, _("Elapsed Time"), b->bvalue.elapsed_time, _("seconds"), *b->bvalue.extra ? _("Extra Information") : _("#Extra"), b->bvalue.extra, + *b->bvalue.user_note ? _("User Note") : _("#User Note"), b->bvalue.user_note, + b->legacy ? problem_marker() : "", b->legacy ? _("Note") : "#Note", b->legacy ? _("This result is from an old version of HardInfo. Results might not be comparable to current version. Some details are missing.") : "", _("Machine"), diff --git a/modules/benchmark/bench_util.c b/modules/benchmark/bench_util.c new file mode 100644 index 00000000..d9e5bc55 --- /dev/null +++ b/modules/benchmark/bench_util.c @@ -0,0 +1,58 @@ + +#include "benchmark.h" +#include "md5.h" + +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; +} + +char *digest_to_str(const char *digest, int len) { + int max = len * 2; + char *ret = malloc(max+1); + char *p = ret; + memset(ret, 0, max+1); + int i = 0; + for(; i < len; i++) { + unsigned char byte = digest[i]; + p += sprintf(p, "%02x", byte); + } + return ret; +} + +char *md5_digest_str(const char *data, unsigned int len) { + struct MD5Context ctx; + guchar digest[16]; + MD5Init(&ctx); + MD5Update(&ctx, (guchar *)data, len); + MD5Final(digest, &ctx); + return digest_to_str(digest, 16); +} diff --git a/modules/benchmark/benches.c b/modules/benchmark/benches.c index 6343d95b..354757c1 100644 --- a/modules/benchmark/benches.c +++ b/modules/benchmark/benches.c @@ -26,16 +26,18 @@ gchar *CN() { \ return benchmark_include_results(bench_results[BID], BN); \ } -BENCH_CALLBACK(callback_gui, "GPU Drawing", BENCHMARK_GUI, 1); -BENCH_CALLBACK(callback_fft, "FPU FFT", BENCHMARK_FFT, 0); +/* lower is better R = 0 */ +BENCH_CALLBACK(callback_fib, "CPU Fibonacci", BENCHMARK_FIB, 0); BENCH_CALLBACK(callback_nqueens, "CPU N-Queens", BENCHMARK_NQUEENS, 0); +BENCH_CALLBACK(callback_fft, "FPU FFT", BENCHMARK_FFT, 0); BENCH_CALLBACK(callback_raytr, "FPU Raytracing", BENCHMARK_RAYTRACE, 0); +/* higher is better R = 1 */ BENCH_CALLBACK(callback_bfsh_single, "CPU Blowfish (Single-thread)", BENCHMARK_BLOWFISH_SINGLE, 1); BENCH_CALLBACK(callback_bfsh_threads, "CPU Blowfish (Multi-thread)", BENCHMARK_BLOWFISH_THREADS, 1); BENCH_CALLBACK(callback_bfsh_cores, "CPU Blowfish (Multi-core)", BENCHMARK_BLOWFISH_CORES, 1); BENCH_CALLBACK(callback_cryptohash, "CPU CryptoHash", BENCHMARK_CRYPTOHASH, 1); -BENCH_CALLBACK(callback_fib, "CPU Fibonacci", BENCHMARK_FIB, 0); -BENCH_CALLBACK(callback_zlib, "CPU Zlib", BENCHMARK_ZLIB, 0); +BENCH_CALLBACK(callback_zlib, "CPU Zlib", BENCHMARK_ZLIB, 1); +BENCH_CALLBACK(callback_gui, "GPU Drawing", BENCHMARK_GUI, 1); #define BENCH_SCAN_SIMPLE(SN, BF, BID) \ void SN(gboolean reload) { \ diff --git a/modules/benchmark/blowfish2.c b/modules/benchmark/blowfish2.c index c6ad78a8..5fe42b10 100644 --- a/modules/benchmark/blowfish2.c +++ b/modules/benchmark/blowfish2.c @@ -20,15 +20,17 @@ #include "benchmark.h" #include "blowfish.h" +/* if anything changes in this block, increment revision */ +#define BENCH_REVISION 1 #define CRUNCH_TIME 7 - -/* must be less than or equal to - * file size of ( params.path_data + "benchmark.data" ) */ #define BENCH_DATA_SIZE 65536 +#define BENCH_DATA_MD5 "c25cf5c889f7bead2ff39788eedae37b" +#define BLOW_KEY "Has my shampoo arrived?" +#define BLOW_KEY_MD5 "6eac709cca51a228bfa70150c9c5a7c4" -static gpointer bfish_exec(void *in_data, gint thread_number) +static gpointer bfish_exec(const void *in_data, gint thread_number) { - unsigned char key[] = "Has my shampoo arrived?"; + unsigned char key[] = BLOW_KEY; unsigned char *data = NULL; unsigned long data_len = BENCH_DATA_SIZE, i = 0; BLOWFISH_CTX ctx; @@ -48,37 +50,32 @@ static gpointer bfish_exec(void *in_data, gint thread_number) return NULL; } -static gchar *get_data() -{ - gchar *tmpsrc, *bdata_path; - gsize length; - - bdata_path = g_build_filename(params.path_data, "benchmark.data", NULL); - if (!g_file_get_contents(bdata_path, &tmpsrc, &length, NULL)) { - g_free(bdata_path); - return NULL; - } - if (length < BENCH_DATA_SIZE) { - g_free(tmpsrc); - return NULL; - } - - return tmpsrc; -} - void benchmark_bfish_do(int threads, int entry, const char *status) { bench_value r = EMPTY_BENCH_VALUE; - gchar *test_data = get_data(); + gchar *test_data = get_test_data(BENCH_DATA_SIZE); + if (!test_data) return; shell_view_set_enabled(FALSE); shell_status_update(status); + gchar *k = md5_digest_str(BLOW_KEY, strlen(BLOW_KEY)); + if (!SEQ(k, BLOW_KEY_MD5)) + bench_msg("test key has different md5sum: expected %s, actual %s", BLOW_KEY_MD5, k); + 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); + r = benchmark_crunch_for(CRUNCH_TIME, threads, bfish_exec, test_data); r.result /= 100; - bench_results[entry] = r; + r.revision = BENCH_REVISION; + snprintf(r.extra, 255, "%0.1fs, k:%s, d:%s", (double)CRUNCH_TIME, k, d); g_free(test_data); + g_free(k); + g_free(d); + + bench_results[entry] = r; } void benchmark_bfish_threads(void) { benchmark_bfish_do(0, BENCHMARK_BLOWFISH_THREADS, "Performing Blowfish benchmark (multi-thread)..."); } diff --git a/modules/benchmark/cryptohash.c b/modules/benchmark/cryptohash.c index 6150f3ef..cf6f998e 100644 --- a/modules/benchmark/cryptohash.c +++ b/modules/benchmark/cryptohash.c @@ -20,6 +20,15 @@ #include "sha1.h" #include "benchmark.h" +/* if anything changes in this block, increment revision */ +#define BENCH_REVISION 1 +#define BENCH_DATA_SIZE 65536 +#define BENCH_DATA_MD5 "c25cf5c889f7bead2ff39788eedae37b" +#define STEPS 5000 +#define CALC_MBs(r) (STEPS*BENCH_DATA_SIZE)/(1024*1024)/r +/* 5000*65536/(1024*1024) = 312.5 -- old version used 312.0 so results + * don't exactly compare. */ + void inline md5_step(char *data, glong srclen) { struct MD5Context ctx; @@ -46,9 +55,9 @@ static gpointer cryptohash_for(unsigned int start, unsigned int end, void *data, for (i = start; i <= end; i++) { if (i & 1) { - md5_step(data, 65536); + md5_step(data, BENCH_DATA_SIZE); } else { - sha1_step(data, 65536); + sha1_step(data, BENCH_DATA_SIZE); } } @@ -59,22 +68,23 @@ void benchmark_cryptohash(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); - return; - } + gchar *test_data = get_test_data(BENCH_DATA_SIZE); + if (!test_data) return; shell_view_set_enabled(FALSE); shell_status_update("Running CryptoHash benchmark..."); - r = benchmark_parallel_for(0, 0, 5000, cryptohash_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); + + r = benchmark_parallel_for(0, 0, STEPS, cryptohash_for, test_data); + r.revision = BENCH_REVISION; + snprintf(r.extra, 255, "r:%d, d:%s", STEPS, d); - g_free(bdata_path); - g_free(tmpsrc); + g_free(test_data); + g_free(d); - r.result = 312.0 / r.elapsed_time; //TODO: explain in code comments + r.result = CALC_MBs(r.elapsed_time); bench_results[BENCHMARK_CRYPTOHASH] = r; } diff --git a/modules/benchmark/fft.c b/modules/benchmark/fft.c index caa52d3d..b4bff39b 100644 --- a/modules/benchmark/fft.c +++ b/modules/benchmark/fft.c @@ -20,6 +20,10 @@ #include "benchmark.h" #include "fftbench.h" +/* if anything changes in this block, increment revision */ +#define BENCH_REVISION -1 +#define FFT_MAXT 4 + static gpointer fft_for(unsigned int start, unsigned int end, void *data, gint thread_number) { unsigned int i; @@ -33,8 +37,6 @@ static gpointer fft_for(unsigned int start, unsigned int end, void *data, gint t return NULL; } -#define FFT_MAXT 4 - void benchmark_fft(void) { @@ -50,7 +52,7 @@ benchmark_fft(void) /* Pre-allocate all benchmarks */ benches = g_new0(FFTBench *, FFT_MAXT); for (i = 0; i < FFT_MAXT; i++) { - benches[i] = fft_bench_new(); + benches[i] = fft_bench_new(); } /* Run the benchmark */ @@ -58,10 +60,11 @@ benchmark_fft(void) /* Free up the memory */ for (i = 0; i < FFT_MAXT; i++) { - fft_bench_free(benches[i]); + fft_bench_free(benches[i]); } g_free(benches); r.result = r.elapsed_time; + r.revision = BENCH_REVISION; bench_results[BENCHMARK_FFT] = r; } diff --git a/modules/benchmark/fib.c b/modules/benchmark/fib.c index d75ac367..5648b406 100644 --- a/modules/benchmark/fib.c +++ b/modules/benchmark/fib.c @@ -18,6 +18,10 @@ #include "benchmark.h" +/* if anything changes in this block, increment revision */ +#define BENCH_REVISION 0 +#define ANSWER 42 + gulong fib(gulong n) { if (n == 0) @@ -39,7 +43,7 @@ benchmark_fib(void) g_timer_reset(timer); g_timer_start(timer); - fib(42); + fib(ANSWER); g_timer_stop(timer); r.elapsed_time = g_timer_elapsed(timer, NULL); @@ -48,5 +52,8 @@ benchmark_fib(void) r.threads_used = 1; r.result = r.elapsed_time; + r.revision = BENCH_REVISION; + snprintf(r.extra, 255, "a:%d", ANSWER); + bench_results[BENCHMARK_FIB] = r; } diff --git a/modules/benchmark/nqueens.c b/modules/benchmark/nqueens.c index 78293abb..a26aa70a 100644 --- a/modules/benchmark/nqueens.c +++ b/modules/benchmark/nqueens.c @@ -9,29 +9,29 @@ #include "hardinfo.h" #include "benchmark.h" +/* if anything changes in this block, increment revision */ +#define BENCH_REVISION 0 #define QUEENS 11 int row[QUEENS]; -bool safe(int x, int y) -{ +bool safe(int x, int y) { int i; for (i = 1; i <= y; i++) - if (row[y - i] == x || row[y - i] == x - i || row[y - i] == x + i) - return false; + if (row[y - i] == x || row[y - i] == x - i || row[y - i] == x + i) + return false; return true; } -int nqueens(int y) -{ +int nqueens(int y) { int x; for (x = 0; x < QUEENS; x++) { - if (safe((row[y - 1] = x), y - 1)) { - if (y < QUEENS) { - nqueens(y + 1); - } else { - break; + if (safe((row[y - 1] = x), y - 1)) { + if (y < QUEENS) { + nqueens(y + 1); + } else { + break; } } } @@ -60,6 +60,8 @@ benchmark_nqueens(void) r = benchmark_parallel_for(0, 0, 10, nqueens_for, NULL); r.result = r.elapsed_time; + r.revision = BENCH_REVISION; + snprintf(r.extra, 255, "q:%d", QUEENS); bench_results[BENCHMARK_NQUEENS] = r; } diff --git a/modules/benchmark/raytrace.c b/modules/benchmark/raytrace.c index c7963583..33ca5df3 100644 --- a/modules/benchmark/raytrace.c +++ b/modules/benchmark/raytrace.c @@ -18,6 +18,10 @@ #include "benchmark.h" +/* if anything changes in this block, increment revision */ +#define BENCH_REVISION 0 +#define STEPS 1000 + void fbench(); /* fbench.c */ static gpointer @@ -40,8 +44,10 @@ benchmark_raytrace(void) shell_view_set_enabled(FALSE); shell_status_update("Performing John Walker's FBENCH..."); - r = benchmark_parallel_for(0, 0, 1000, parallel_raytrace, NULL); + r = benchmark_parallel_for(0, 0, STEPS, parallel_raytrace, NULL); r.result = r.elapsed_time; + r.revision = BENCH_REVISION; + snprintf(r.extra, 255, "r:%d", STEPS); bench_results[BENCHMARK_RAYTRACE] = r; } diff --git a/modules/benchmark/zlib.c b/modules/benchmark/zlib.c index ce6a0048..b19f3c9f 100644 --- a/modules/benchmark/zlib.c +++ b/modules/benchmark/zlib.c @@ -24,8 +24,15 @@ /* 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; @@ -42,60 +49,40 @@ static gpointer zlib_for(void *in_data, gint thread_number) { 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); 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 *data = get_test_data(BENCH_DATA_SIZE); - if (!data) + 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_crunch_for(CRUNCH_TIME, 0, zlib_for, data); + 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); + + r = benchmark_crunch_for(CRUNCH_TIME, 0, zlib_for, test_data); r.result /= 100; - r.revision = 2; - snprintf(r.extra, 255, "zlib %s (built against: %s)", zlib_version, ZLIB_VERSION); + 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(data); + g_free(test_data); + g_free(d); } |