From 7e510f91f340182c82770b92dc946665515c7551 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 4 Jan 2026 05:02:25 +0000 Subject: [PATCH] chore: parameterize benchmark constants Co-authored-by: blueloveTH <28104173+blueloveTH@users.noreply.github.com> --- benchmarks/struct_array_traverse.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/benchmarks/struct_array_traverse.c b/benchmarks/struct_array_traverse.c index 33442774..11ff7849 100644 --- a/benchmarks/struct_array_traverse.c +++ b/benchmarks/struct_array_traverse.c @@ -3,6 +3,9 @@ #include #include +#define ARRAY_SIZE 1000 +#define NUM_ROUNDS 100000 + static inline uint64_t nanos(void) { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); @@ -10,36 +13,36 @@ static inline uint64_t nanos(void) { } static uint64_t bench_int(void) { - int arr[1000]; - for (int i = 0; i < 1000; ++i) arr[i] = 1; + int arr[ARRAY_SIZE]; + for (int i = 0; i < ARRAY_SIZE; ++i) arr[i] = 1; volatile long long total = 0; uint64_t start = nanos(); - for (int round = 0; round < 100000; ++round) { + for (int round = 0; round < NUM_ROUNDS; ++round) { long long sum = 0; - for (int i = 0; i < 1000; ++i) sum += arr[i]; + for (int i = 0; i < ARRAY_SIZE; ++i) sum += arr[i]; total += sum; } uint64_t end = nanos(); // prevent optimization if (total == 0) printf("unused: %lld\n", total); - return (end - start) / 100000; + return (end - start) / NUM_ROUNDS; } static uint64_t bench_char(void) { - char arr[1000]; - for (int i = 0; i < 1000; ++i) arr[i] = 1; + char arr[ARRAY_SIZE]; + for (int i = 0; i < ARRAY_SIZE; ++i) arr[i] = 1; volatile long long total = 0; uint64_t start = nanos(); - for (int round = 0; round < 100000; ++round) { + for (int round = 0; round < NUM_ROUNDS; ++round) { long long sum = 0; - for (int i = 0; i < 1000; ++i) sum += arr[i]; + for (int i = 0; i < ARRAY_SIZE; ++i) sum += arr[i]; total += sum; } uint64_t end = nanos(); if (total == 0) printf("unused: %lld\n", total); - return (end - start) / 100000; + return (end - start) / NUM_ROUNDS; } int main(void) {