diff options
Diffstat (limited to 'modules/benchmark')
-rw-r--r-- | modules/benchmark/bench_results.c | 109 | ||||
-rw-r--r-- | modules/benchmark/benches.c | 106 | ||||
-rw-r--r-- | modules/benchmark/blowfish.c | 45 | ||||
-rw-r--r-- | modules/benchmark/cryptohash.c | 33 | ||||
-rw-r--r-- | modules/benchmark/drawing.c | 8 | ||||
-rw-r--r-- | modules/benchmark/fft.c | 36 | ||||
-rw-r--r-- | modules/benchmark/fib.c | 20 | ||||
-rw-r--r-- | modules/benchmark/nqueens.c | 23 | ||||
-rw-r--r-- | modules/benchmark/raytrace.c | 19 | ||||
-rw-r--r-- | modules/benchmark/zlib.c | 26 |
10 files changed, 288 insertions, 137 deletions
diff --git a/modules/benchmark/bench_results.c b/modules/benchmark/bench_results.c index 226f595c..27a33a65 100644 --- a/modules/benchmark/bench_results.c +++ b/modules/benchmark/bench_results.c @@ -32,13 +32,12 @@ typedef struct { int cores; int threads; char *mid; -} simple_machine; +} bench_machine; typedef struct { char *name; - float result; - int threads; - simple_machine *machine; + bench_value bvalue; + bench_machine *machine; int legacy; /* an old benchmark.conf result */ } bench_result; @@ -112,7 +111,7 @@ static int cpu_config_is_close(char *str0, char *str1) { return 0; } -static gen_machine_id(simple_machine *m) { +static gen_machine_id(bench_machine *m) { char *s; if (m) { if (m->mid != NULL) @@ -135,19 +134,19 @@ static gen_machine_id(simple_machine *m) { } } -simple_machine *simple_machine_new() { - simple_machine *m = NULL; - m = malloc(sizeof(simple_machine)); +bench_machine *bench_machine_new() { + bench_machine *m = NULL; + m = malloc(sizeof(bench_machine)); if (m) - memset(m, 0, sizeof(simple_machine)); + memset(m, 0, sizeof(bench_machine)); return m; } -simple_machine *simple_machine_this() { - simple_machine *m = NULL; +bench_machine *bench_machine_this() { + bench_machine *m = NULL; char *tmp; - m = simple_machine_new(); + m = bench_machine_new(); if (m) { m->board = module_call_method("devices::getMotherboard"); m->cpu_name = module_call_method("devices::getProcessorName"); @@ -159,18 +158,12 @@ simple_machine *simple_machine_this() { free(tmp); cpu_procs_cores_threads(&m->processors, &m->cores, &m->threads); - /* - tmp = module_call_method("devices::getProcessorCount"); - m->threads = atoi(tmp); - free(tmp); - */ - gen_machine_id(m); } return m; } -void simple_machine_free(simple_machine *s) { +void bench_machine_free(bench_machine *s) { if (s) { free(s->board); free(s->cpu_name); @@ -183,20 +176,19 @@ void simple_machine_free(simple_machine *s) { void bench_result_free(bench_result *s) { if (s) { free(s->name); - simple_machine_free(s->machine); + bench_machine_free(s->machine); } } -bench_result *bench_result_this_machine(const char *bench_name, float result, int threads) { +bench_result *bench_result_this_machine(const char *bench_name, bench_value r) { bench_result *b = NULL; b = malloc(sizeof(bench_result)); if (b) { memset(b, 0, sizeof(bench_result)); - b->machine = simple_machine_this(); + b->machine = bench_machine_this(); b->name = strdup(bench_name); - b->result = result; - b->threads = threads; + b->bvalue = r; b->legacy = 0; } return b; @@ -221,6 +213,32 @@ static int nx_prefix(const char *str) { return -1; } +/* old results didn't store the actual number of threads used */ +static int guess_threads_old_result(const char *bench_name, int threads_available) { +#define CHKBNAME(BN) (strcmp(bench_name, BN) == 0) + if (CHKBNAME("CPU Fibonacci") ) + return 1; + if (CHKBNAME("FPU FFT") ) { + if (threads_available >= 4) + return 4; + else if (threads_available >= 2) + return 2; + else + return 1; + } + if (CHKBNAME("CPU N-Queens") ) { + if (threads_available >= 10) + return 10; + else if (threads_available >= 5) + return 5; + else if (threads_available >= 2) + return 2; + else + return 1; + } + return threads_available; +} + bench_result *bench_result_benchmarkconf(const char *section, const char *key, char **values) { bench_result *b = NULL; char *s0, *s1, *s2; @@ -232,13 +250,16 @@ bench_result *bench_result_benchmarkconf(const char *section, const char *key, c b = malloc(sizeof(bench_result)); if (b) { memset(b, 0, sizeof(bench_result)); - b->machine = simple_machine_new(); + b->machine = bench_machine_new(); b->name = strdup(section); if (vl >= 10) { /* the 11th could be empty */ b->machine->mid = strdup(key); - b->result = atof(values[0]); - b->threads = atoi(values[1]); + /* first try as bench_value, then try as double 'result' only */ + b->bvalue = bench_value_from_str(values[0]); + if (b->bvalue.result == -1) + b->bvalue.result = atoi(values[0]); + b->bvalue.threads_used = atoi(values[1]); b->machine->board = strdup(values[2]); b->machine->cpu_name = strdup(values[3]); b->machine->cpu_desc = strdup(values[4]); @@ -251,7 +272,7 @@ bench_result *bench_result_benchmarkconf(const char *section, const char *key, c b->machine->ogl_renderer = strdup(values[10]); b->legacy = 0; } else if (vl >= 2) { - b->result = atof(values[0]); + b->bvalue.result = atof(values[0]); b->legacy = 1; /* old old format has prefix before cpu name (ex: 4x Pentium...) */ @@ -259,11 +280,9 @@ bench_result *bench_result_benchmarkconf(const char *section, const char *key, c if (nx > 0) { b->machine->cpu_name = strdup(strchr(key, 'x') + 1); b->machine->threads = nx; - b->threads = nx; } else { b->machine->cpu_name = strdup(key); b->machine->threads = 1; - b->threads = 1; } b->machine->cpu_config = strdup(values[1]); @@ -271,9 +290,10 @@ bench_result *bench_result_benchmarkconf(const char *section, const char *key, c nx = nx_prefix(values[1]); if (nx > 0) { b->machine->threads = nx; - b->threads = nx; } + b->bvalue.threads_used = guess_threads_old_result(section, b->machine->threads); + /* If the clock rate in the id string is more than the * config string, use that. Older hardinfo used current cpu freq * instead of max freq. @@ -295,7 +315,7 @@ bench_result *bench_result_benchmarkconf(const char *section, const char *key, c n = atof(s1+1); n *= m; - s1 = g_strdup_printf("%dx %.2f %s", b->threads, n, _("MHz")); + s1 = g_strdup_printf("%dx %.2f %s", b->bvalue.threads_used, n, _("MHz")); if ( cpu_config_cmp(b->machine->cpu_config, s1) == -1 && !cpu_config_is_close(b->machine->cpu_config, s1) ) { free(b->machine->cpu_config); @@ -327,8 +347,9 @@ bench_result *bench_result_benchmarkconf(const char *section, const char *key, c char *bench_result_benchmarkconf_line(bench_result *b) { char *cpu_config = cpu_config_retranslate(b->machine->cpu_config, 1, 0); - char *ret = g_strdup_printf("%s=%.2f|%d|%s|%s|%s|%s|%d|%d|%d|%d|%s\n", - b->machine->mid, b->result, b->threads, + char *bv = bench_value_to_str(b->bvalue); + char *ret = g_strdup_printf("%s=%s|%d|%s|%s|%s|%s|%d|%d|%d|%d|%s\n", + b->machine->mid, bv, b->bvalue.threads_used, (b->machine->board != NULL) ? b->machine->board : "", b->machine->cpu_name, (b->machine->cpu_desc != NULL) ? b->machine->cpu_desc : "", @@ -338,10 +359,11 @@ char *bench_result_benchmarkconf_line(bench_result *b) { (b->machine->ogl_renderer != NULL) ? b->machine->ogl_renderer : "" ); free(cpu_config); + free(bv); return ret; } -char *bench_result_more_info(bench_result *b) { +static char *bench_result_more_info_less(bench_result *b) { char *memory = (b->machine->memory_kiB > 0) ? g_strdup_printf("%d %s", b->machine->memory_kiB, _("kiB") ) @@ -359,7 +381,7 @@ char *bench_result_more_info(bench_result *b) { /* ogl rend */ "%s=%s\n" /* mem */ "%s=%s\n", _("Benchmark Result"), - _("Threads"), b->threads, + _("Threads"), b->bvalue.threads_used, 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"), @@ -375,11 +397,12 @@ char *bench_result_more_info(bench_result *b) { return ret; } -char *bench_result_more_info_complete(bench_result *b) { +static char *bench_result_more_info_complete(bench_result *b) { return g_strdup_printf("[%s]\n" /* bench name */"%s=%s\n" - /* result */ "%s=%0.2f\n" /* threads */ "%s=%d\n" + /* result */ "%s=%0.2f\n" + /* elapsed */ "%s=%0.2f\n" /* legacy */ "%s=%s\n" "[%s]\n" /* board */ "%s=%s\n" @@ -394,8 +417,9 @@ char *bench_result_more_info_complete(bench_result *b) { /* cfg_val */ "%s=%.2f\n", _("Benchmark Result"), _("Benchmark"), b->name, - _("Result"), b->result, - _("Threads"), b->threads, + _("Threads"), b->bvalue.threads_used, + _("Result"), b->bvalue.result, + _("Elapsed Time"), b->bvalue.elapsed_time, 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"), @@ -411,3 +435,8 @@ char *bench_result_more_info_complete(bench_result *b) { _("cfg_val"), cpu_config_val(b->machine->cpu_config) ); } + +char *bench_result_more_info(bench_result *b) { + //return bench_result_more_info_complete(b); + return bench_result_more_info_less(b); +} diff --git a/modules/benchmark/benches.c b/modules/benchmark/benches.c new file mode 100644 index 00000000..e09dedcc --- /dev/null +++ b/modules/benchmark/benches.c @@ -0,0 +1,106 @@ +/* + * HardInfo - Displays System Information + * Copyright (C) 2003-2017 Leandro A. F. Pereira <leandro@hardinfo.org> + * + * 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. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* These are parts of modules/benchmark.c where specific benchmarks are defined. */ + +#define BENCH_CALLBACK(CN, BN, BID, R) \ +gchar *CN() { \ + if (R) \ + return benchmark_include_results_reverse(bench_results[BID], BN); \ + else \ + 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); +BENCH_CALLBACK(callback_nqueens, "CPU N-Queens", BENCHMARK_NQUEENS, 0); +BENCH_CALLBACK(callback_raytr, "FPU Raytracing", BENCHMARK_RAYTRACE, 0); +BENCH_CALLBACK(callback_bfsh, "CPU Blowfish", BENCHMARK_BLOWFISH, 0); +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); + +#define BENCH_SCAN_SIMPLE(SN, BF, BID) \ +void SN(gboolean reload) { \ + SCAN_START(); \ + do_benchmark(BF, BID); \ + SCAN_END(); \ +} + +BENCH_SCAN_SIMPLE(scan_fft, benchmark_fft, BENCHMARK_FFT); +BENCH_SCAN_SIMPLE(scan_nqueens, benchmark_nqueens, BENCHMARK_NQUEENS); +BENCH_SCAN_SIMPLE(scan_raytr, benchmark_raytrace, BENCHMARK_RAYTRACE); +BENCH_SCAN_SIMPLE(scan_bfsh, benchmark_fish, BENCHMARK_BLOWFISH); +BENCH_SCAN_SIMPLE(scan_cryptohash, benchmark_cryptohash, BENCHMARK_CRYPTOHASH); +BENCH_SCAN_SIMPLE(scan_fib, benchmark_fib, BENCHMARK_FIB); +BENCH_SCAN_SIMPLE(scan_zlib, benchmark_zlib, BENCHMARK_ZLIB); + +void scan_gui(gboolean reload) +{ + SCAN_START(); + + bench_value er = EMPTY_BENCH_VALUE; + + if (params.run_benchmark) { + int argc = 0; + + ui_init(&argc, NULL); + } + + if (params.gui_running || params.run_benchmark) { + do_benchmark(benchmark_gui, BENCHMARK_GUI); + } else { + bench_results[BENCHMARK_GUI] = er; + } + SCAN_END(); +} + +static ModuleEntry entries[] = { + {N_("CPU Blowfish"), "blowfish.png", callback_bfsh, scan_bfsh, MODULE_FLAG_NONE}, + {N_("CPU CryptoHash"), "cryptohash.png", callback_cryptohash, scan_cryptohash, MODULE_FLAG_NONE}, + {N_("CPU Fibonacci"), "nautilus.png", callback_fib, scan_fib, MODULE_FLAG_NONE}, + {N_("CPU N-Queens"), "nqueens.png", callback_nqueens, scan_nqueens, MODULE_FLAG_NONE}, + {N_("CPU Zlib"), "file-roller.png", callback_zlib, scan_zlib, MODULE_FLAG_NONE}, + {N_("FPU FFT"), "fft.png", callback_fft, scan_fft, MODULE_FLAG_NONE}, + {N_("FPU Raytracing"), "raytrace.png", callback_raytr, scan_raytr, MODULE_FLAG_NONE}, +#if !GTK_CHECK_VERSION(3,0,0) + {N_("GPU Drawing"), "module.png", callback_gui, scan_gui, MODULE_FLAG_NO_REMOTE}, +#endif + {NULL} +}; + +const gchar *hi_note_func(gint entry) +{ + switch (entry) { + case BENCHMARK_CRYPTOHASH: + return _("Results in MiB/second. Higher is better."); + + case BENCHMARK_ZLIB: + case BENCHMARK_GUI: + return _("Results in HIMarks. Higher is better."); + + case BENCHMARK_FFT: + case BENCHMARK_RAYTRACE: + case BENCHMARK_BLOWFISH: + case BENCHMARK_FIB: + case BENCHMARK_NQUEENS: + return _("Results in seconds. Lower is better."); + } + + return NULL; +} diff --git a/modules/benchmark/blowfish.c b/modules/benchmark/blowfish.c index feadc430..2aa11a2a 100644 --- a/modules/benchmark/blowfish.c +++ b/modules/benchmark/blowfish.c @@ -15,8 +15,8 @@ You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - + + COMMENTS ON USING THIS CODE: @@ -31,7 +31,7 @@ Normal usage is as follows: [4] Decryption is the same as encryption except that the plaintext and ciphertext are reversed. -Warning #1: The code does not check key lengths. (Caveat encryptor.) +Warning #1: The code does not check key lengths. (Caveat encryptor.) Warning #2: Beware that Blowfish keys repeat such that "ab" = "abab". Warning #3: It is normally a good idea to zeroize the BLOWFISH_CTX before freeing it. @@ -41,33 +41,33 @@ Warning #4: Endianness conversions are the responsibility of the caller. Warning #5: Make sure to use a reasonable mode of operation for your application. (If you don't know what CBC mode is, see Warning #7.) Warning #6: This code is susceptible to timing attacks. -Warning #7: Security engineering is risky and non-intuitive. Have someone +Warning #7: Security engineering is risky and non-intuitive. Have someone check your work. If you don't know what you are doing, get help. This is code is fast enough for most applications, but is not optimized for speed. -If you require this code under a license other than LGPL, please ask. (I -can be located using your favorite search engine.) Unfortunately, I do not -have time to provide unpaid support for everyone who uses this code. +If you require this code under a license other than LGPL, please ask. (I +can be located using your favorite search engine.) Unfortunately, I do not +have time to provide unpaid support for everyone who uses this code. -- Paul Kocher -*/ - +*/ + #include "hardinfo.h" #include "benchmark.h" #include "blowfish.h" - + #define N 16 static const unsigned long ORIG_P[16 + 2] = { 0x243F6A88L, 0x85A308D3L, 0x13198A2EL, 0x03707344L, 0xA4093822L, 0x299F31D0L, 0x082EFA98L, 0xEC4E6C89L, 0x452821E6L, 0x38D01377L, 0xBE5466CFL, 0x34E90C6CL, 0xC0AC29B7L, - 0xC97C50DDL, 0x3F84D5B5L, 0xB5470917L, 0x9216D5D9L, 0x8979FB1BL + 0xC97C50DDL, 0x3F84D5B5L, 0xB5470917L, 0x9216D5D9L, 0x8979FB1BL }; -static const unsigned long ORIG_S[4][256] = { +static const unsigned long ORIG_S[4][256] = { {0xD1310BA6L, 0x98DFB5ACL, 0x2FFD72DBL, 0xD01ADFB7L, 0xB8E1AFEDL, 0x6A267E96L, 0xBA7C9045L, 0xF12C7F99L, 0x24A19947L, 0xB3916CF7L, 0x0801F2E2L, 0x858EFC16L, 0x636920D8L, 0x71574E69L, 0xA458FEA3L, @@ -383,7 +383,7 @@ static const unsigned long ORIG_S[4][256] = { 0x85CBFE4EL, 0x8AE88DD8L, 0x7AAAF9B0L, 0x4CF9AA7EL, 0x1948C25CL, 0x02FB8A8CL, 0x01C36AE4L, 0xD6EBE1F9L, 0x90D4F869L, 0xA65CDEA0L, 0x3F09252DL, 0xC208E69FL, 0xB74E6132L, 0xCE77E25BL, 0x578FDFE3L, - 0x3AC372E6L} + 0x3AC372E6L} }; static unsigned long F(BLOWFISH_CTX * ctx, unsigned long x) @@ -440,14 +440,14 @@ void Blowfish_Decrypt(BLOWFISH_CTX * ctx, unsigned long *xl, for (i = N + 1; i > 1; --i) { Xl = Xl ^ ctx->P[i]; Xr = F(ctx, Xl) ^ Xr; - - /* Exchange Xl and Xr */ + + /* Exchange Xl and Xr */ temp = Xl; Xl = Xr; Xr = temp; } - - /* Exchange Xl and Xr */ + + /* Exchange Xl and Xr */ temp = Xl; Xl = Xr; Xr = temp; @@ -502,7 +502,7 @@ parallel_blowfish(unsigned int start, unsigned int end, void *data, gint thread_ L = 0xBEBACAFE; R = 0xDEADBEEF; - for (i = start; i <= end; i++) { + for (i = start; i <= end; i++) { Blowfish_Init(&ctx, (unsigned char*)data, 65536); Blowfish_Encrypt(&ctx, &L, &R); Blowfish_Decrypt(&ctx, &L, &R); @@ -514,12 +514,14 @@ parallel_blowfish(unsigned int start, unsigned int end, void *data, gint thread_ void benchmark_fish(void) { + bench_value r = EMPTY_BENCH_VALUE; + gchar *tmpsrc; gchar *bdata_path; bdata_path = g_build_filename(params.path_data, "benchmark.data", NULL); if (!g_file_get_contents(bdata_path, &tmpsrc, NULL, NULL)) { - bench_results[BENCHMARK_BLOWFISH] = -1.0f; + bench_results[BENCHMARK_BLOWFISH] = r; g_free(bdata_path); return; } @@ -527,7 +529,10 @@ benchmark_fish(void) shell_view_set_enabled(FALSE); shell_status_update("Performing Blowfish benchmark..."); - bench_results[BENCHMARK_BLOWFISH] = benchmark_parallel_for(0, 50000, parallel_blowfish, tmpsrc); + r = benchmark_parallel_for(0, 0, 50000, parallel_blowfish, tmpsrc); + r.result = r.elapsed_time; + + bench_results[BENCHMARK_BLOWFISH] = r; g_free(bdata_path); g_free(tmpsrc); } diff --git a/modules/benchmark/cryptohash.c b/modules/benchmark/cryptohash.c index d97e85c7..6150f3ef 100644 --- a/modules/benchmark/cryptohash.c +++ b/modules/benchmark/cryptohash.c @@ -20,21 +20,21 @@ #include "sha1.h" #include "benchmark.h" -static void inline md5_step(char *data, glong srclen) +void inline md5_step(char *data, glong srclen) { struct MD5Context ctx; guchar checksum[16]; - + MD5Init(&ctx); MD5Update(&ctx, (guchar *)data, srclen); MD5Final(checksum, &ctx); } -static void inline sha1_step(char *data, glong srclen) +void inline sha1_step(char *data, glong srclen) { SHA1_CTX ctx; guchar checksum[20]; - + SHA1Init(&ctx); SHA1Update(&ctx, (guchar*)data, srclen); SHA1Final(checksum, &ctx); @@ -43,37 +43,38 @@ static void inline sha1_step(char *data, glong srclen) static gpointer cryptohash_for(unsigned int start, unsigned int end, void *data, gint thread_number) { unsigned int i; - - for (i = start; i <= end; i++) { + + for (i = start; i <= end; i++) { if (i & 1) { md5_step(data, 65536); } else { sha1_step(data, 65536); } } - + return NULL; } void benchmark_cryptohash(void) { - gdouble elapsed = 0; + 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; - } - + } + shell_view_set_enabled(FALSE); shell_status_update("Running CryptoHash benchmark..."); - - elapsed = benchmark_parallel_for(0, 5000, cryptohash_for, tmpsrc); - + + r = benchmark_parallel_for(0, 0, 5000, cryptohash_for, tmpsrc); + g_free(bdata_path); g_free(tmpsrc); - - bench_results[BENCHMARK_CRYPTOHASH] = 312.0 / elapsed; + + r.result = 312.0 / r.elapsed_time; //TODO: explain in code comments + bench_results[BENCHMARK_CRYPTOHASH] = r; } diff --git a/modules/benchmark/drawing.c b/modules/benchmark/drawing.c index 67a2c264..d0905954 100644 --- a/modules/benchmark/drawing.c +++ b/modules/benchmark/drawing.c @@ -22,8 +22,12 @@ void benchmark_gui(void) { + bench_value r = EMPTY_BENCH_VALUE; + shell_view_set_enabled(FALSE); shell_status_update("Running drawing benchmark..."); - - bench_results[BENCHMARK_GUI] = guibench(); + + r.result = guibench(); //TODO: explain in code comments + + bench_results[BENCHMARK_GUI] = r; } diff --git a/modules/benchmark/fft.c b/modules/benchmark/fft.c index 7c5889c8..caa52d3d 100644 --- a/modules/benchmark/fft.c +++ b/modules/benchmark/fft.c @@ -25,43 +25,43 @@ static gpointer fft_for(unsigned int start, unsigned int end, void *data, gint t unsigned int i; FFTBench **benches = (FFTBench **)data; FFTBench *fftbench = (FFTBench *)(benches[thread_number]); - - for (i = start; i <= end; i++) { + + for (i = start; i <= end; i++) { fft_bench_run(fftbench); } - + return NULL; } +#define FFT_MAXT 4 + void benchmark_fft(void) { - gdouble elapsed = 0; + bench_value r = EMPTY_BENCH_VALUE; + int n_cores, i; gchar *temp; FFTBench **benches; - + shell_view_set_enabled(FALSE); shell_status_update("Running FFT benchmark..."); - + /* Pre-allocate all benchmarks */ - temp = module_call_method("devices::getProcessorCount"); - n_cores = temp ? atoi(temp) : 1; - g_free(temp); - - benches = g_new0(FFTBench *, n_cores); - for (i = 0; i < n_cores; i++) { + benches = g_new0(FFTBench *, FFT_MAXT); + for (i = 0; i < FFT_MAXT; i++) { benches[i] = fft_bench_new(); } - + /* Run the benchmark */ - elapsed = benchmark_parallel_for(0, 4, fft_for, benches); - + r = benchmark_parallel_for(FFT_MAXT, 0, FFT_MAXT, fft_for, benches); + /* Free up the memory */ - for (i = 0; i < n_cores; i++) { + for (i = 0; i < FFT_MAXT; i++) { fft_bench_free(benches[i]); } g_free(benches); - - bench_results[BENCHMARK_FFT] = elapsed; + + r.result = r.elapsed_time; + bench_results[BENCHMARK_FFT] = r; } diff --git a/modules/benchmark/fib.c b/modules/benchmark/fib.c index 0f88be59..d75ac367 100644 --- a/modules/benchmark/fib.c +++ b/modules/benchmark/fib.c @@ -18,8 +18,7 @@ #include "benchmark.h" -static gulong -fib(gulong n) +gulong fib(gulong n) { if (n == 0) return 0; @@ -32,19 +31,22 @@ void benchmark_fib(void) { GTimer *timer = g_timer_new(); - gdouble elapsed; - + bench_value r = EMPTY_BENCH_VALUE; + shell_view_set_enabled(FALSE); shell_status_update("Calculating the 42nd Fibonacci number..."); - + g_timer_reset(timer); g_timer_start(timer); fib(42); - + g_timer_stop(timer); - elapsed = g_timer_elapsed(timer, NULL); + r.elapsed_time = g_timer_elapsed(timer, NULL); g_timer_destroy(timer); - - bench_results[BENCHMARK_FIB] = elapsed; + + r.threads_used = 1; + r.result = r.elapsed_time; + + bench_results[BENCHMARK_FIB] = r; } diff --git a/modules/benchmark/nqueens.c b/modules/benchmark/nqueens.c index a32ed8c1..78293abb 100644 --- a/modules/benchmark/nqueens.c +++ b/modules/benchmark/nqueens.c @@ -25,7 +25,7 @@ bool safe(int x, 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) { @@ -35,32 +35,33 @@ int nqueens(int y) } } } - + return 0; } static gpointer nqueens_for(unsigned int start, unsigned int end, void *data, gint thread_number) { unsigned int i; - - for (i = start; i <= end; i++) { + + for (i = start; i <= end; i++) { nqueens(0); } - + return NULL; } void benchmark_nqueens(void) { - gdouble elapsed = 0; - + bench_value r = EMPTY_BENCH_VALUE; + shell_view_set_enabled(FALSE); shell_status_update("Running N-Queens benchmark..."); - - elapsed = benchmark_parallel_for(0, 10, nqueens_for, NULL); - - bench_results[BENCHMARK_NQUEENS] = elapsed; + + r = benchmark_parallel_for(0, 0, 10, nqueens_for, NULL); + r.result = r.elapsed_time; + + bench_results[BENCHMARK_NQUEENS] = r; } diff --git a/modules/benchmark/raytrace.c b/modules/benchmark/raytrace.c index 2ee36a93..c7963583 100644 --- a/modules/benchmark/raytrace.c +++ b/modules/benchmark/raytrace.c @@ -24,24 +24,25 @@ static gpointer parallel_raytrace(unsigned int start, unsigned int end, gpointer data, gint thread_number) { unsigned int i; - - for (i = start; i <= end; i++) { + + for (i = start; i <= end; i++) { fbench(); } - + return NULL; } void benchmark_raytrace(void) { - gdouble elapsed = 0; - + bench_value r = EMPTY_BENCH_VALUE; + shell_view_set_enabled(FALSE); shell_status_update("Performing John Walker's FBENCH..."); - - elapsed = benchmark_parallel_for(0, 1000, parallel_raytrace, NULL); - - bench_results[BENCHMARK_RAYTRACE] = elapsed; + + r = benchmark_parallel_for(0, 0, 1000, parallel_raytrace, NULL); + r.result = r.elapsed_time; + + bench_results[BENCHMARK_RAYTRACE] = r; } diff --git a/modules/benchmark/zlib.c b/modules/benchmark/zlib.c index eeec9d0e..2ded59a4 100644 --- a/modules/benchmark/zlib.c +++ b/modules/benchmark/zlib.c @@ -31,8 +31,8 @@ static gpointer zlib_for(unsigned int start, unsigned int end, void *data, gint compressed = malloc(bound); if (!compressed) return NULL; - - for (i = start; i <= end; i++) { + + for (i = start; i <= end; i++) { char uncompressed[65536]; uLong compressedBound = bound; uLong destBound = sizeof(uncompressed); @@ -42,30 +42,32 @@ static gpointer zlib_for(unsigned int start, unsigned int end, void *data, gint } free(compressed); - + return NULL; } void benchmark_zlib(void) { - gdouble elapsed = 0; + 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; - } - + } + shell_view_set_enabled(FALSE); shell_status_update("Running Zlib benchmark..."); - - elapsed = benchmark_parallel_for(0, 50000, zlib_for, tmpsrc); - + + r = benchmark_parallel_for(0, 0, 50000, zlib_for, tmpsrc); + g_free(bdata_path); g_free(tmpsrc); - gdouble marks = (50000. * 65536.) / (elapsed * 840205128.); - bench_results[BENCHMARK_ZLIB] = marks; + //TODO: explain in code comments + gdouble marks = (50000. * 65536.) / (r.elapsed_time * 840205128.); + r.result = marks; + bench_results[BENCHMARK_ZLIB] = r; } |