aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeandro Pereira <leandro@hardinfo.org>2012-01-27 09:59:57 -0200
committerLeandro Pereira <leandro@hardinfo.org>2012-01-27 09:59:57 -0200
commitb2e6f23b7be1154227276f42c0fd59eaa1a07d52 (patch)
tree6e15dc531407d4f59be22a0814ebc39ff34542bc
parentcd7e7199a885327e4594e88b9b3fdddbb8fd2cee (diff)
Fix weird results in benchmark values
gcc was (correctly) assuming that benchmark_parallel_for() returned an integer, which was being to a double and messing up results. Added the missing prototype. Also, populate bench_results array with sane values on module init. Some other minor cleanups in benchmark code.
-rw-r--r--includes/benchmark.h3
-rw-r--r--modules/benchmark.c20
-rw-r--r--modules/benchmark/blowfish.c8
3 files changed, 22 insertions, 9 deletions
diff --git a/includes/benchmark.h b/includes/benchmark.h
index 5f72874a..8047d5c6 100644
--- a/includes/benchmark.h
+++ b/includes/benchmark.h
@@ -25,6 +25,9 @@ void benchmark_gui(void);
void benchmark_nqueens(void);
void benchmark_raytrace(void);
+gdouble benchmark_parallel_for(guint start, guint end,
+ gpointer callback, gpointer callback_data);
+
extern gdouble bench_results[BENCHMARK_N_ENTRIES];
#endif /* __BENCHMARK_H__ */ \ No newline at end of file
diff --git a/modules/benchmark.c b/modules/benchmark.c
index 9d4e80d7..fffc0864 100644
--- a/modules/benchmark.c
+++ b/modules/benchmark.c
@@ -67,7 +67,7 @@ struct _ParallelBenchTask {
gpointer data, callback;
};
-gpointer benchmark_parallel_for_dispatcher(gpointer data)
+static gpointer benchmark_parallel_for_dispatcher(gpointer data)
{
ParallelBenchTask *pbt = (ParallelBenchTask *)data;
gpointer (*callback)(unsigned int start, unsigned int end, void *data, gint thread_number);
@@ -133,7 +133,7 @@ gdouble benchmark_parallel_for(guint start, guint end,
thread = g_thread_create((GThreadFunc) benchmark_parallel_for_dispatcher,
pbt, TRUE, NULL);
- threads = g_slist_append(threads, thread);
+ threads = g_slist_prepend(threads, thread);
DEBUG("thread %d launched as context %p", thread_number, thread);
}
@@ -319,6 +319,8 @@ static gboolean do_benchmark_handler(GIOChannel *source,
BenchmarkDialog *bench_dialog = (BenchmarkDialog*)data;
GIOStatus status;
gchar *result;
+ gchar *buffer;
+ float float_result;
status = g_io_channel_read_line(source, &result, NULL, NULL, NULL);
if (status != G_IO_STATUS_NORMAL) {
@@ -329,7 +331,14 @@ static gboolean do_benchmark_handler(GIOChannel *source,
return FALSE;
}
- bench_dialog->result = atof(result);
+ float_result = strtof(result, &buffer);
+ if (buffer == result) {
+ DEBUG("error while converting floating point value");
+ bench_dialog->result = -1.0f;
+ } else {
+ bench_dialog->result = float_result;
+ }
+
gtk_widget_destroy(bench_dialog->dialog);
g_free(result);
@@ -635,6 +644,11 @@ void hi_module_init(void)
sync_manager_add_entry(&se[0]);
sync_manager_add_entry(&se[1]);
+
+ int i;
+ for (i = 0; i < G_N_ELEMENTS(entries) - 1; i++) {
+ bench_results[i] = -1.0f;
+ }
}
gchar **hi_module_get_dependencies(void)
diff --git a/modules/benchmark/blowfish.c b/modules/benchmark/blowfish.c
index b18b3570..feadc430 100644
--- a/modules/benchmark/blowfish.c
+++ b/modules/benchmark/blowfish.c
@@ -514,13 +514,12 @@ parallel_blowfish(unsigned int start, unsigned int end, void *data, gint thread_
void
benchmark_fish(void)
{
- gdouble elapsed = 0;
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;
g_free(bdata_path);
return;
}
@@ -528,10 +527,7 @@ benchmark_fish(void)
shell_view_set_enabled(FALSE);
shell_status_update("Performing Blowfish benchmark...");
- elapsed = benchmark_parallel_for(0, 50000, parallel_blowfish, tmpsrc);
-
+ bench_results[BENCHMARK_BLOWFISH] = benchmark_parallel_for(0, 50000, parallel_blowfish, tmpsrc);
g_free(bdata_path);
g_free(tmpsrc);
-
- bench_results[BENCHMARK_BLOWFISH] = elapsed;
}