aboutsummaryrefslogtreecommitdiff
path: root/modules/benchmark/nqueens.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/nqueens.c
parent09fcc751ef158898c315ebc9299a0fa3a722d914 (diff)
New upstream version 2.0.3preupstream/2.0.3pre
Diffstat (limited to 'modules/benchmark/nqueens.c')
-rw-r--r--modules/benchmark/nqueens.c41
1 files changed, 21 insertions, 20 deletions
diff --git a/modules/benchmark/nqueens.c b/modules/benchmark/nqueens.c
index 78293abb..6aad7638 100644
--- a/modules/benchmark/nqueens.c
+++ b/modules/benchmark/nqueens.c
@@ -9,29 +9,30 @@
#include "hardinfo.h"
#include "benchmark.h"
-#define QUEENS 11
+/* if anything changes in this block, increment revision */
+#define BENCH_REVISION 2
+#define QUEENS 6
+#define CRUNCH_TIME 5
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;
}
}
}
@@ -39,13 +40,9 @@ int nqueens(int y)
return 0;
}
-static gpointer nqueens_for(unsigned int start, unsigned int end, void *data, gint thread_number)
+static gpointer nqueens_for(void *data, gint thread_number)
{
- unsigned int i;
-
- for (i = start; i <= end; i++) {
- nqueens(0);
- }
+ nqueens(0);
return NULL;
}
@@ -58,9 +55,13 @@ benchmark_nqueens(void)
shell_view_set_enabled(FALSE);
shell_status_update("Running N-Queens benchmark...");
- r = benchmark_parallel_for(0, 0, 10, nqueens_for, NULL);
- r.result = r.elapsed_time;
+ r = benchmark_crunch_for(CRUNCH_TIME, 0, nqueens_for, NULL);
+
+ r.revision = BENCH_REVISION;
+ snprintf(r.extra, 255, "q:%d", QUEENS);
+ r.result /= 25;
+
bench_results[BENCHMARK_NQUEENS] = r;
}