Skip to content

Commit 54603f2

Browse files
committed
Improve t-test handling by multiple contexts
Previously, a single 't_context_t' instance was used for all statistical tests, limiting the ability to assess multiple cropping thresholds independently. This change allows separate t-tests for different percentiles of execution times, ensuring more robust statistical analysis. To achieve this, the following changes were made: - Replaced the single 't_context_t' instance with an array 'ctxs[]' to track multiple contexts. - Introduced 'DUDECT_TESTS' to define the total number of tests, including the baseline. - Updated 'update_statistics()' to push values into the appropriate context based on percentile filtering. - Implemented 'max_test()' to determine the test context with the maximum t-value. - Adjusted memory allocation and cleanup for multiple contexts. This enhances the ability to detect timing differences at various thresholds, improving test reliability. Change-Id: Icfad85854765316dece6d1303c5e13ad1e8ab8e9
1 parent 0c920f9 commit 54603f2

File tree

1 file changed

+36
-11
lines changed

1 file changed

+36
-11
lines changed

dudect/fixture.c

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,12 @@
4242

4343
#define ENOUGH_MEASURE 10000
4444
#define TEST_TRIES 10
45+
46+
/* Number of percentiles to calculate */
4547
#define NUM_PERCENTILES (100)
48+
#define DUDECT_TESTS (NUM_PERCENTILES + 1)
4649

47-
static t_context_t *t;
50+
static t_context_t *ctxs[DUDECT_TESTS];
4851

4952
/* threshold values for Welch's t-test */
5053
enum {
@@ -70,10 +73,10 @@ static int cmp(const int64_t *a, const int64_t *b)
7073
}
7174

7275
/* This function is used to set different thresholds for cropping measurements.
73-
* To filter out the slowest measurements, we keep only the fastest ones by a
74-
* complementary exponential decay scale as threshold for cropping measurements:
75-
* threshold(x) = 1 - 0.5^(10 * x / N_MEASURES), where x is the counter of the measurement.
76-
* This way we will have more tolerance for the first measurements and less for the last ones.
76+
* To filter out slow measurements, we keep only the fastest ones by a
77+
* complementary exponential decay scale as thresholds for cropping
78+
* measurements: threshold(x) = 1 - 0.5^(10 * x / N_MEASURES), where x is the
79+
* counter of the measurement.
7780
*/
7881
static void prepare_percentiles(int64_t *exec_times, int64_t *percentiles)
7982
{
@@ -106,19 +109,35 @@ static void update_statistics(const int64_t *exec_times,
106109
continue;
107110

108111
/* do a t-test on the execution time */
109-
t_push(t, difference, classes[i]);
112+
t_push(ctxs[0], difference, classes[i]);
110113

111-
/* t-test on cropped execution times, for several cropping thresholds. */
114+
/* t-test on cropped execution times, for several cropping thresholds.
115+
*/
112116
for (size_t j = 0; j < NUM_PERCENTILES; j++) {
113117
if (difference < percentiles[j]) {
114-
t_push(t, difference, classes[i]);
118+
t_push(ctxs[j + 1], difference, classes[i]);
115119
}
116120
}
117121
}
118122
}
119123

124+
static t_context_t *max_test()
125+
{
126+
size_t max_idx = 0;
127+
double max_t = 0.0f;
128+
for (size_t i = 0; i < NUM_PERCENTILES + 1; i++) {
129+
double t = fabs(t_compute(ctxs[i]));
130+
if (t > max_t) {
131+
max_t = t;
132+
max_idx = i;
133+
}
134+
}
135+
return ctxs[max_idx];
136+
}
137+
120138
static bool report(void)
121139
{
140+
t_context_t *t = max_test();
122141
double max_t = fabs(t_compute(t));
123142
double number_traces_max_t = t->n[0] + t->n[1];
124143
double max_tau = max_t / sqrt(number_traces_max_t);
@@ -191,13 +210,15 @@ static bool doit(int mode)
191210
static void init_once(void)
192211
{
193212
init_dut();
194-
t_init(t);
213+
for (size_t i = 0; i < DUDECT_TESTS; i++) {
214+
ctxs[i] = malloc(sizeof(t_context_t));
215+
t_init(ctxs[i]);
216+
}
195217
}
196218

197219
static bool test_const(char *text, int mode)
198220
{
199221
bool result = false;
200-
t = malloc(sizeof(t_context_t));
201222

202223
for (int cnt = 0; cnt < TEST_TRIES; ++cnt) {
203224
printf("Testing %s...(%d/%d)\n\n", text, cnt, TEST_TRIES);
@@ -209,7 +230,11 @@ static bool test_const(char *text, int mode)
209230
if (result)
210231
break;
211232
}
212-
free(t);
233+
234+
for (size_t i = 0; i < DUDECT_TESTS; i++) {
235+
free(ctxs[i]);
236+
}
237+
213238
return result;
214239
}
215240

0 commit comments

Comments
 (0)