From f26c216349e9e6687b5acd3a490a3db891d0b33d Mon Sep 17 00:00:00 2001 From: Scott McKendry <39483124+scottmckendry@users.noreply.github.com> Date: Mon, 9 Dec 2024 09:17:54 +1300 Subject: [PATCH] improve rounding logic for benchmarks in readme --- 2024/utils/utils.odin | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/2024/utils/utils.odin b/2024/utils/utils.odin index 6217bbe..d268105 100644 --- a/2024/utils/utils.odin +++ b/2024/utils/utils.odin @@ -58,28 +58,29 @@ get_solution_stats :: proc(solutions: map[string]proc()) -> []solution_stat { i_stat += 1 } - run_once := []string{"06P2:Guard Gallivant"} - slice.sort(ordered_keys) for key, i in ordered_keys { solution := solutions[key] sum_ex_time := time.Duration(0) - if slice.contains(run_once, key) { + for j := 0; j < 10; j += 1 { sum_ex_time += benchmark(solution) + } + + exec_time := time.Duration(sum_ex_time / 10) + if sum_ex_time / 10 >= time.Second { + exec_time = time.duration_round(sum_ex_time / 10, time.Millisecond * 100) // round to nearest .1 second for >1s + } else if sum_ex_time / 10 >= time.Millisecond { + exec_time = time.duration_round(sum_ex_time / 10, time.Microsecond * 100) // round to nearest .1 millisecond for >1ms } else { - for j := 0; j < 10; j += 1 { - sum_ex_time += benchmark(solution) - } + exec_time = time.duration_round(sum_ex_time / 10, time.Microsecond) // round to nearest microsecond for <1ms } stats[i] = solution_stat { name = strings.split(key, ":", context.temp_allocator)[1], day = strings.split(key, ":", context.temp_allocator)[0][0:2], part = strings.split(key, ":", context.temp_allocator)[0][3:4], - execution_time = time.Duration( - time.duration_round((sum_ex_time / 10), time.Microsecond), - ), + execution_time = time.Duration(exec_time), } }