From 3553148174ceb9c01eec1ca660aa77d5f0bd0b0e Mon Sep 17 00:00:00 2001 From: goksu <25721443+goeksu@users.noreply.github.com> Date: Fri, 18 Aug 2023 02:04:38 +0300 Subject: [PATCH] detecting outliers --- builds/testing.mk | 2 +- src/tools/ftbench/ftbench.c | 75 +++++++++++++++++-------- src/tools/ftbench/src/tohtml.py | 99 ++++++++++++++++++++++++++++++++- 3 files changed, 149 insertions(+), 27 deletions(-) diff --git a/builds/testing.mk b/builds/testing.mk index b5e79b07a..55288e4af 100644 --- a/builds/testing.mk +++ b/builds/testing.mk @@ -3,7 +3,7 @@ FTBENCH_DIR = $(TOP_DIR)/src/tools/ftbench FTBENCH_SRC = $(FTBENCH_DIR)/ftbench.c FTBENCH_OBJ = $(OBJ_DIR)/bench.$(SO) FTBENCH_BIN = $(OBJ_DIR)/bench$E -FTBENCH_FLAG ?= -c 1000 -w 100 +FTBENCH_FLAG ?= -c 550 -w 50 INCLUDES = $(TOP_DIR)/include FONTS = $(wildcard $(FTBENCH_DIR)/fonts/*.ttf) BASELINE_DIR = $(OBJ_DIR)/baseline/ diff --git a/src/tools/ftbench/ftbench.c b/src/tools/ftbench/ftbench.c index c7126ae9f..8b2188131 100644 --- a/src/tools/ftbench/ftbench.c +++ b/src/tools/ftbench/ftbench.c @@ -260,11 +260,18 @@ #define TIMER_GET( timer ) ( timer )->total #define TIMER_RESET( timer ) ( timer )->total = 0 +#define CHUNK_SIZE 100 +int compare(const void* a, const void* b) { + if (*(double*)a > *(double*)b) return 1; + if (*(double*)a < *(double*)b) return -1; + return 0; +} /* * Bench code */ + static void benchmark( FT_Face face, btest_t* test, @@ -276,6 +283,8 @@ int n, done; btimer_t timer, elapsed; + int NUM_CHUNKS = max_iter / CHUNK_SIZE; + double results[NUM_CHUNKS]; if ( test->cache_first ) { @@ -283,39 +292,59 @@ test->bench( &timer, face, test->user_data ); } + // Initial warm-up + for (n = 0; n < warmup; n++) { + test->bench(&timer, face, test->user_data); + } + printf( " %-25s ", test->title ); fflush( stdout ); - TIMER_RESET( &timer ); - TIMER_RESET( &elapsed ); - int is_warmup = 1; - - for ( n = 0, done = 0; !max_iter || n < max_iter; n++ ) - { - if ( is_warmup && n == warmup ){ - is_warmup = 0; + for (int chunk = 0; chunk < NUM_CHUNKS; chunk++) { TIMER_RESET( &timer ); TIMER_RESET( &elapsed ); - } - - TIMER_START( &elapsed ); + // Execute a chunk of iterations + for (n = 0, done = 0; n < CHUNK_SIZE; n++) { + TIMER_START( &elapsed ); + done += test->bench( &timer, face, test->user_data ); + TIMER_STOP( &elapsed ); - done += test->bench( &timer, face, test->user_data ); - - TIMER_STOP( &elapsed ); - - - if (!is_warmup && TIMER_GET( &elapsed ) > 1E6 * max_time ) - break; + + } + if (TIMER_GET( &elapsed ) > 1E6 * max_time) { + //break; + } + results[chunk] = TIMER_GET( &timer ); } - if ( done ) - printf( "%10.1f microseconds %10d done\n", - TIMER_GET( &timer ), done ); - else - printf( "no error-free calls\n" ); + // Sort results for IQR calculation + qsort(results, NUM_CHUNKS, sizeof(double), compare); + + double q1 = results[NUM_CHUNKS / 4]; + double q3 = results[3 * NUM_CHUNKS / 4]; + double iqr = q3 - q1; + double lower_bound = q1 - 1.5 * iqr; + double upper_bound = q3 + 1.5 * iqr; + + double total_time = 0.0; + int valid_chunks = 0; + + for (int chunk = 0; chunk < NUM_CHUNKS; chunk++) { + if (results[chunk] >= lower_bound && results[chunk] <= upper_bound) { + total_time += results[chunk]; + valid_chunks++; + } + } + + double average_time = total_time / valid_chunks; + + + + printf( "%10.1f microseconds %10d done\n", + average_time, done ); + } diff --git a/src/tools/ftbench/src/tohtml.py b/src/tools/ftbench/src/tohtml.py index 3fc01db60..61205a671 100644 --- a/src/tools/ftbench/src/tohtml.py +++ b/src/tools/ftbench/src/tohtml.py @@ -55,6 +55,9 @@ def main(): generate_info_table(html_file, baseline_info, benchmark_info) + # Generate total results table + generate_total_results_table(html_file, BASELINE_DIR, BENCHMARK_DIR) + # Generate results tables for filename in os.listdir(BASELINE_DIR): if filename.endswith(".txt") and not filename == "info.txt": @@ -64,6 +67,8 @@ def main(): generate_results_table( html_file, baseline_results, benchmark_results, filename ) + + write_to_html(html_file, "