From 49410f52640ae55530fd1ddad7b238299ee439e1 Mon Sep 17 00:00:00 2001 From: Minseong Jang Date: Thu, 12 Jun 2025 13:36:46 +0900 Subject: [PATCH 1/2] Change initial data range --- bench/multiply.c | 4 ++-- bench/qsort.c | 2 +- bench/rsort.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bench/multiply.c b/bench/multiply.c index 9ef782f..802a51f 100644 --- a/bench/multiply.c +++ b/bench/multiply.c @@ -14,8 +14,8 @@ void multiply_data_init(int nonce) { int y = nonce; for (i = 0; i < 100; i++) { - x = (x * 97 + 17) % 10009; - y = (y * 17 + 23) % 10007; + x = (x * 97 + 17) % 1009; + y = (y * 17 + 23) % 1007; input1_multiply[i] = x; input2_multiply[i] = y; } diff --git a/bench/qsort.c b/bench/qsort.c index 956feaa..e2f2f44 100644 --- a/bench/qsort.c +++ b/bench/qsort.c @@ -12,7 +12,7 @@ void qsort_data_init(int nonce) { int x = nonce; for (i = 0; i < 16384; i++) { - x = (x * 97 + 17) % 100000009; + x = (x * 97 + 17) % 100009; input_qsort_data[i] = x; } } diff --git a/bench/rsort.c b/bench/rsort.c index 737d924..11f27c9 100644 --- a/bench/rsort.c +++ b/bench/rsort.c @@ -12,7 +12,7 @@ void rsort_data_init(int nonce) { int x = nonce; for (i = 0; i < 2048; i++) { - x = (x * 97 + 17) % 10000007; + x = (x * 97 + 17) % 100007; input_rsort_data[i] = x; } } From 1aa18bce300b40a213c540988a4c4234d73244cb Mon Sep 17 00:00:00 2001 From: Minseong Jang Date: Fri, 13 Jun 2025 15:19:21 +0900 Subject: [PATCH 2/2] Update benchmarks --- bench/exotic_arguments.c | 60 +++++++------- bench/fibonacci.c | 52 ++++++------- bench/graph.c | 151 +++++++++++++++++++----------------- bench/matrix.c | 82 ++++++++++---------- bench/median.c | 2 +- bench/multiply.c | 5 +- bench/qsort.c | 2 +- bench/rsort.c | 2 +- bench/spmv.c | 2 +- bench/two_dimension_array.c | 34 ++++---- bench/vvadd.c | 2 +- 11 files changed, 201 insertions(+), 193 deletions(-) diff --git a/bench/exotic_arguments.c b/bench/exotic_arguments.c index 037df87..936907a 100644 --- a/bench/exotic_arguments.c +++ b/bench/exotic_arguments.c @@ -1,59 +1,59 @@ typedef struct { - int a; - int b; + int a; + int b; } small; typedef struct { - long a; - long b; - long c; - long d; - long e; - long f; - long g; - long h; + long a; + long b; + long c; + long d; + long e; + long f; + long g; + long h; } large; typedef struct { - long a; - float b; + long a; + float b; } small_ugly; typedef struct { - long a; - float b; - long c; - double d; - long e; - long f; - long g; - double h; - long i; - long j; - long k; - double l; + long a; + float b; + long c; + double d; + long e; + long f; + long g; + double h; + long i; + long j; + long k; + double l; } large_ugly; int exotic_arguments_struct_small(small a, int nonce) { - return a.a + a.b + nonce; + return a.a + a.b + nonce; } long exotic_arguments_struct_large(large a, int nonce) { - return a.a + a.b + a.c + a.d + a.e + a.f + a.g + a.h + nonce; + return a.a + a.b + a.c + a.d + a.e + a.f + a.g + a.h + nonce; } float exotic_arguments_struct_small_ugly(small_ugly a, int nonce) { - return 0.0f + a.a + a.b + nonce; + return 0.0f + a.a + a.b + nonce; } double exotic_arguments_struct_large_ugly(large_ugly a, int nonce) { - return 0.0 + a.a + a.b + a.c + a.d + a.e + a.f + a.g + a.h + nonce; + return 0.0 + a.a + a.b + a.c + a.d + a.e + a.f + a.g + a.h + nonce; } float exotic_arguments_float(float a, int nonce) { - return a + (float) nonce; + return a + (float)nonce; } double exotic_arguments_double(double a, int nonce) { - return a + (double) nonce; + return a + (double)nonce; } diff --git a/bench/fibonacci.c b/bench/fibonacci.c index 78d0cb1..e11df13 100644 --- a/bench/fibonacci.c +++ b/bench/fibonacci.c @@ -1,36 +1,36 @@ int fibonacci_loop(int n, int nonce) { - int result = 0; + int result = 0; - for (int step = 0; step < 10; ++step) { - int x = nonce; - int y = nonce; + for (int step = 0; step < 10; ++step) { + int x = nonce; + int y = nonce; - for (int i = 1; i < n; ++i) { - int newy = x + y; - newy += (x + y); - newy += (x + y); - newy += (x + y); - newy += (x + y); - newy += (x + y); - newy -= (x + y); - newy -= (x + y); - newy -= (x + y); - newy -= (x + y); - newy -= (x + y); - x = y; - y = newy; + for (int i = 1; i < n; ++i) { + int newy = x + y; + newy += (x + y); + newy += (x + y); + newy += (x + y); + newy += (x + y); + newy += (x + y); + newy -= (x + y); + newy -= (x + y); + newy -= (x + y); + newy -= (x + y); + newy -= (x + y); + x = y; + y = newy; + } + + result += y; } - result += y; - } - - return result; + return result; } int fibonacci_recursive(int n, int nonce) { - if (n < 2) { - return nonce; - } + if (n < 2) { + return nonce; + } - return fibonacci_recursive(n - 1, nonce) + fibonacci_recursive(n - 2, nonce); + return fibonacci_recursive(n - 1, nonce) + fibonacci_recursive(n - 2, nonce); } diff --git a/bench/graph.c b/bench/graph.c index 7e48574..17b1fa6 100644 --- a/bench/graph.c +++ b/bench/graph.c @@ -2,96 +2,101 @@ int graph_weight[1000][1000]; int graph_dijkstra_dist[1000]; int graph_dijkstra_visited[1000]; -void graph_weight_init(int n, int nonce, int *x, int (*weight)[1000]) { - for (int i = 0; i < n; ++i) { - weight[i][i] = 0; - - for (int j = 1; j < n; ++j) { - weight[i][(i + j) % n] = ++*x; +void graph_weight_init(int n, int nonce, int* x, int (*weight)[1000]) { + for (int i = 0; i < n; ++i) { + weight[i][i] = 0; - if (*x % (nonce + 1)) { - ++*x; - } + for (int j = 1; j < n; ++j) { + weight[i][(i + j) % n] = ++*x; + + if (*x % (nonce + 1)) { + ++*x; + } + } } - } } int graph_dijkstra(int n, int nonce) { - if (!(n <= 1000)) { - return nonce; - } - - int x = 0; - graph_weight_init(n, nonce, &x, graph_weight); - - for (int i = 0; i < n; ++i) { - graph_dijkstra_dist[i] = -1; - graph_dijkstra_visited[i] = 0; - } - graph_dijkstra_dist[0] = 0; - - for (int step = 0; step < n; ++step) { - int v = -1; - for (int i = 0; i < n; ++i) { - if (!(graph_dijkstra_dist[i] != -1 && !graph_dijkstra_visited[i])) { - continue; - } - - if (v != -1 && graph_dijkstra_dist[v] < graph_dijkstra_dist[i]) { - continue; - } - - v = i; + if (!(n <= 1000)) { + return nonce; } - if (v == -1) { - break; - } - - int dist = graph_dijkstra_dist[v]; - graph_dijkstra_visited[v] = 1; + int x = 0; + graph_weight_init(n, nonce, &x, graph_weight); for (int i = 0; i < n; ++i) { - if (graph_dijkstra_visited[i]) continue; - if (graph_dijkstra_dist[i] != -1 && graph_dijkstra_dist[i] < dist + graph_weight[v][i]) continue; - graph_dijkstra_dist[i] = dist + graph_weight[v][i]; + graph_dijkstra_dist[i] = -1; + graph_dijkstra_visited[i] = 0; } - } + graph_dijkstra_dist[0] = 0; - int result = 0; - for (int i = 0; i < n; ++i) { - result += graph_dijkstra_dist[i]; - } + for (int step = 0; step < n; ++step) { + int v = -1; + for (int i = 0; i < n; ++i) { + if (!(graph_dijkstra_dist[i] != -1 && !graph_dijkstra_visited[i])) { + continue; + } - return result; + if (v != -1 && graph_dijkstra_dist[v] < graph_dijkstra_dist[i]) { + continue; + } + + v = i; + } + + if (v == -1) { + break; + } + + int dist = graph_dijkstra_dist[v]; + graph_dijkstra_visited[v] = 1; + + for (int i = 0; i < n; ++i) { + if (graph_dijkstra_visited[i]) + continue; + if (graph_dijkstra_dist[i] != -1 && graph_dijkstra_dist[i] < dist + graph_weight[v][i]) + continue; + graph_dijkstra_dist[i] = dist + graph_weight[v][i]; + } + } + + int result = 0; + for (int i = 0; i < n; ++i) { + result ^= graph_dijkstra_dist[i]; + } + + return result; } int graph_floyd_warshall(int n, int nonce) { - if (!(n <= 1000)) { - return nonce; - } + if (!(n <= 1000)) { + return nonce; + } - int x = 0; - graph_weight_init(n, nonce, &x, graph_weight); + int x = 0; + graph_weight_init(n, nonce, &x, graph_weight); - for (int k = 0; k < n; ++k) { + for (int k = 0; k < n; ++k) { + for (int i = 0; i < n; ++i) { + if (graph_weight[i][k] == -1) + continue; + + for (int j = 0; j < n; ++j) { + if (graph_weight[k][j] == -1) + continue; + int weight = graph_weight[i][k] + graph_weight[k][j]; + if (graph_weight[i][j] != -1 && graph_weight[i][j] < weight) + continue; + graph_weight[i][j] = weight; + } + } + } + + int result = 0; for (int i = 0; i < n; ++i) { - if (graph_weight[i][k] == -1) continue; - - for (int j = 0; j < n; ++j) { - if (graph_weight[k][j] == -1) continue; - int weight = graph_weight[i][k] + graph_weight[k][j]; - if (graph_weight[i][j] != -1 && graph_weight[i][j] < weight) continue; - graph_weight[i][j] = weight; - } + for (int j = 0; j < n; ++j) { + result ^= graph_weight[i][j]; + } } - } - - int result = 0; - for (int i = 0; i < n; ++i) { - for (int j = 0; j < n; ++j) { - result += graph_weight[i][j]; - } - } - return result; + return result; } diff --git a/bench/matrix.c b/bench/matrix.c index 2d2a183..ac4a5c4 100644 --- a/bench/matrix.c +++ b/bench/matrix.c @@ -2,57 +2,57 @@ int matrix_a[30][30]; int matrix_b[30][30]; int matrix_c[30][30]; -void matrix_init(int n, int nonce, int *x, int (*matrix)[30]) { - for (int i = 0; i < n; ++i) { - for (int j = 0; j < n; ++j) { - matrix[i][j] = ++*x; +void matrix_init(int n, int nonce, int* x, int (*matrix)[30]) { + for (int i = 0; i < n; ++i) { + for (int j = 0; j < n; ++j) { + matrix[i][j] = ++*x; - if (*x % (nonce + 1)) { - ++*x; - } + if (*x % (nonce + 1)) { + ++*x; + } + } } - } } int matrix_mul(int n, int nonce) { - if (!(n <= 30)) { - return nonce; - } - - int x = 0; - matrix_init(n, nonce, &x, matrix_a); - matrix_init(n, nonce, &x, matrix_b); - - int result = 0; - for (int i = 0; i < n; ++i) { - for (int j = 0; j < n; ++j) { - matrix_c[i][j] = 0; - for (int k = 0; k < n; ++k) { - matrix_c[i][j] += matrix_a[i][k] * matrix_b[k][j]; - } - result += matrix_c[i][j]; + if (!(n <= 30)) { + return nonce; } - } - return result; + int x = 0; + matrix_init(n, nonce, &x, matrix_a); + matrix_init(n, nonce, &x, matrix_b); + + int result = 0; + for (int i = 0; i < n; ++i) { + for (int j = 0; j < n; ++j) { + matrix_c[i][j] = 0; + for (int k = 0; k < n; ++k) { + matrix_c[i][j] += matrix_a[i][k] * matrix_b[k][j]; + } + result ^= matrix_c[i][j]; + } + } + + return result; } int matrix_add(int n, int nonce) { - if (!(n <= 30)) { - return nonce; - } - - int x = 0; - matrix_init(n, nonce, &x, matrix_a); - matrix_init(n, nonce, &x, matrix_b); - - int result = 0; - for (int i = 0; i < n; ++i) { - for (int j = 0; j < n; ++j) { - matrix_c[i][j] = matrix_a[i][j] + nonce * matrix_b[i][j]; - result += matrix_c[i][j]; + if (!(n <= 30)) { + return nonce; } - } - return result; + int x = 0; + matrix_init(n, nonce, &x, matrix_a); + matrix_init(n, nonce, &x, matrix_b); + + int result = 0; + for (int i = 0; i < n; ++i) { + for (int j = 0; j < n; ++j) { + matrix_c[i][j] = matrix_a[i][j] + nonce * matrix_b[i][j]; + result ^= matrix_c[i][j]; + } + } + + return result; } diff --git a/bench/median.c b/bench/median.c index 173b5d5..342649d 100644 --- a/bench/median.c +++ b/bench/median.c @@ -56,7 +56,7 @@ int verify_median(int n, int* test) { for (i = 0; i < n; i++) { int v = test[i]; - result += v; + result ^= v; } return result; diff --git a/bench/multiply.c b/bench/multiply.c index 802a51f..d7a5619 100644 --- a/bench/multiply.c +++ b/bench/multiply.c @@ -26,6 +26,9 @@ int multiply(int x, int y) { int result = 0; for (i = 0; i < 32; i++) { + if (x == 0) + break; + if ((x & 0x1) == 1) result = result + y; @@ -47,7 +50,7 @@ int verify_multiply(int n, int* test) { if (t0 * t1 != v) return 1; - result += v; + result ^= v; } return result; diff --git a/bench/qsort.c b/bench/qsort.c index e2f2f44..27bc9bf 100644 --- a/bench/qsort.c +++ b/bench/qsort.c @@ -115,7 +115,7 @@ int verify_qsort(int n, int* test) { if (t0 > t1) return 1; - result += t0; + result ^= t0; } return result; diff --git a/bench/rsort.c b/bench/rsort.c index 11f27c9..b943ef5 100644 --- a/bench/rsort.c +++ b/bench/rsort.c @@ -101,7 +101,7 @@ int verify_rsort(int n, int* test) { if (t0 > t1) return 1; - result += t0; + result ^= t0; } return result; diff --git a/bench/spmv.c b/bench/spmv.c index 6179bf3..1b72850 100644 --- a/bench/spmv.c +++ b/bench/spmv.c @@ -74,7 +74,7 @@ int verifyDouble(int n, double* test) { int result = 0; for (i = 0; i < n; i++) { - result += (int) (test[i]); + result ^= (int) (test[i]); } return result; diff --git a/bench/two_dimension_array.c b/bench/two_dimension_array.c index 652000e..a4d5928 100644 --- a/bench/two_dimension_array.c +++ b/bench/two_dimension_array.c @@ -1,24 +1,24 @@ int two_dimension_array_arr[100]; int two_dimension_array(int n, int nonce) { - if (!(n <= 100)) { - return nonce; - } - - for (int i = 0; i < n; ++i) { - two_dimension_array_arr[i] = i + nonce; - } - - for (int i = 0; i < n; ++i) { - for (int j = 0; j < n; ++j) { - two_dimension_array_arr[i] += two_dimension_array_arr[j]; + if (!(n <= 100)) { + return nonce; } - } - int result = 0; - for (int i = 0; i < n; ++i) { - result += two_dimension_array_arr[i]; - } + for (int i = 0; i < n; ++i) { + two_dimension_array_arr[i] = i + nonce; + } - return result; + for (int i = 0; i < n; ++i) { + for (int j = 0; j < n; ++j) { + two_dimension_array_arr[i] ^= two_dimension_array_arr[j]; + } + } + + int result = 0; + for (int i = 0; i < n; ++i) { + result += two_dimension_array_arr[i]; + } + + return result; } diff --git a/bench/vvadd.c b/bench/vvadd.c index adb0b3b..8aab712 100644 --- a/bench/vvadd.c +++ b/bench/vvadd.c @@ -35,7 +35,7 @@ int verify_vvadd(int n, int* test) { for (i = 0; i < n; i++) { int v = test[i]; - result += v; + result ^= v; } return result;