From 56fd56dc02a348f717461ffdaa8673a97bfbdb82 Mon Sep 17 00:00:00 2001 From: Jusufadis Bakamovic Date: Thu, 11 Apr 2019 11:48:29 +0200 Subject: Refactor U-Test calculation into separate function. (#740) * Refactor U-Test calculation into separate function. And implement 'print_utest' functionality in terms of it. * Change 'optimal_repetitions' to 'more_optimal_repetitions'. --- tools/gbench/report.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/tools/gbench/report.py b/tools/gbench/report.py index 49b46ec..5bd3a8d 100644 --- a/tools/gbench/report.py +++ b/tools/gbench/report.py @@ -154,11 +154,7 @@ def extract_field(partition, field_name): rhs = [x[field_name] for x in partition[1]] return [lhs, rhs] - -def print_utest(partition, utest_alpha, first_col_width, use_color=True): - timings_time = extract_field(partition, 'real_time') - timings_cpu = extract_field(partition, 'cpu_time') - +def calc_utest(timings_cpu, timings_time): min_rep_cnt = min(len(timings_time[0]), len(timings_time[1]), len(timings_cpu[0]), @@ -166,21 +162,33 @@ def print_utest(partition, utest_alpha, first_col_width, use_color=True): # Does *everything* has at least UTEST_MIN_REPETITIONS repetitions? if min_rep_cnt < UTEST_MIN_REPETITIONS: - return [] - - def get_utest_color(pval): - return BC_FAIL if pval >= utest_alpha else BC_OKGREEN + return False, None, None time_pvalue = mannwhitneyu( timings_time[0], timings_time[1], alternative='two-sided').pvalue cpu_pvalue = mannwhitneyu( timings_cpu[0], timings_cpu[1], alternative='two-sided').pvalue + return (min_rep_cnt >= UTEST_OPTIMAL_REPETITIONS), cpu_pvalue, time_pvalue + +def print_utest(partition, utest_alpha, first_col_width, use_color=True): + def get_utest_color(pval): + return BC_FAIL if pval >= utest_alpha else BC_OKGREEN + + timings_time = extract_field(partition, 'real_time') + timings_cpu = extract_field(partition, 'cpu_time') + have_optimal_repetitions, cpu_pvalue, time_pvalue = calc_utest(timings_cpu, timings_time) + + # Check if we failed miserably with minimum required repetitions for utest + if not have_optimal_repetitions and cpu_pvalue is None and time_pvalue is None: + return [] + dsc = "U Test, Repetitions: {} vs {}".format( len(timings_cpu[0]), len(timings_cpu[1])) dsc_color = BC_OKGREEN - if min_rep_cnt < UTEST_OPTIMAL_REPETITIONS: + # We still got some results to show but issue a warning about it. + if not have_optimal_repetitions: dsc_color = BC_WARNING dsc += ". WARNING: Results unreliable! {}+ repetitions recommended.".format( UTEST_OPTIMAL_REPETITIONS) -- cgit v1.2.3