From 3312405ada1ad4184c7552e41adfb1fdbd412c56 Mon Sep 17 00:00:00 2001 From: MikeChen Date: Sat, 28 Jun 2025 14:35:18 +0800 Subject: [PATCH] Fix incorrect DROP_SIZE usage Previously, measure() only recorded timings for indices in the middle range [DROP_SIZE, N_MEASURES - DROP_SIZE), while update_statistics() assumed all entries were starting available from index 10. This mismatch allowed zero-valued exec_times from unmeasured head and tail indices to be included in the t-test, reducing sample means, inflating variances, and suppressing the t-value, which may lead to incorrect results or prevent detection thresholds from being reached. After the fix, all samples are measured and update_statistics() discards DROP_SIZE samples at both ends. This ensures correct sample accounting, prevents overestimating the number of measurements required, and avoids false negatives due to uninitialized timing data. Change-Id: Ibb1515043da5f56d72fe34fd5c78e2283df9a993 --- dudect/constant.c | 10 +++++----- dudect/fixture.c | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dudect/constant.c b/dudect/constant.c index f6f1e95eb..976000d8b 100644 --- a/dudect/constant.c +++ b/dudect/constant.c @@ -77,7 +77,7 @@ bool measure(int64_t *before_ticks, switch (mode) { case DUT(insert_head): - for (size_t i = DROP_SIZE; i < N_MEASURES - DROP_SIZE; i++) { + for (size_t i = 0; i < N_MEASURES; i++) { char *s = get_random_string(); dut_new(); dut_insert_head( @@ -94,7 +94,7 @@ bool measure(int64_t *before_ticks, } break; case DUT(insert_tail): - for (size_t i = DROP_SIZE; i < N_MEASURES - DROP_SIZE; i++) { + for (size_t i = 0; i < N_MEASURES; i++) { char *s = get_random_string(); dut_new(); dut_insert_head( @@ -111,7 +111,7 @@ bool measure(int64_t *before_ticks, } break; case DUT(remove_head): - for (size_t i = DROP_SIZE; i < N_MEASURES - DROP_SIZE; i++) { + for (size_t i = 0; i < N_MEASURES; i++) { dut_new(); dut_insert_head( get_random_string(), @@ -129,7 +129,7 @@ bool measure(int64_t *before_ticks, } break; case DUT(remove_tail): - for (size_t i = DROP_SIZE; i < N_MEASURES - DROP_SIZE; i++) { + for (size_t i = 0; i < N_MEASURES; i++) { dut_new(); dut_insert_head( get_random_string(), @@ -147,7 +147,7 @@ bool measure(int64_t *before_ticks, } break; default: - for (size_t i = DROP_SIZE; i < N_MEASURES - DROP_SIZE; i++) { + for (size_t i = 0; i < N_MEASURES; i++) { dut_new(); dut_insert_head( get_random_string(), diff --git a/dudect/fixture.c b/dudect/fixture.c index bf6ce8f31..34bc551e9 100644 --- a/dudect/fixture.c +++ b/dudect/fixture.c @@ -103,7 +103,7 @@ static void update_statistics(const int64_t *exec_times, uint8_t *classes, int64_t *percentiles) { - for (size_t i = 0; i < N_MEASURES; i++) { + for (size_t i = DROP_SIZE; i < N_MEASURES - DROP_SIZE; i++) { int64_t difference = exec_times[i]; /* CPU cycle counter overflowed or dropped measurement */ if (difference <= 0)