From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by sourceware.org (Postfix) with ESMTPS id 9B88A3858D39 for ; Mon, 3 Apr 2023 15:34:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9B88A3858D39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-x529.google.com with SMTP id w9so118993614edc.3 for ; Mon, 03 Apr 2023 08:34:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680536060; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Pra/9k4IBbu3ixpMXZyKDFbfLK3rxmRy5+dU+M2lijo=; b=g4x5Nq959q3ngrEOc98pOwczGB4rqTrpxcwr6hQ/GBjool1TQr/UymOpMGFt5dXBdh iU+A13m92046696L4pObrI+h5lnrDLUN2VmoAdB4bHYP6NtMlTmp0u8cfoXKz2u3OtEO DNPSE0VzHqBGs04+qClqz2SXRD0yMF5123dgPrMWujcuxlkFZuFI3TSR3q+IfRLSpmJ0 FAysrCxBzcB2E6Ss6xqBkfS7NUO2rKQv1zqtZAVtVITxAusjN9yL02SR8+YkXx0qS1Yn h73i1AJLczN4vjMMDuKHbgVRwgm2VDGGOrUnv7a0Jz3m2s61+ckZegwJdAiPRVE9DXru oIHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680536060; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Pra/9k4IBbu3ixpMXZyKDFbfLK3rxmRy5+dU+M2lijo=; b=nYUcpSZ0BAw9I4AM5pISd8OMFULrsR8C+rvPY1wywREYxhp9TBcFdNnovgp46XY56u 9rHFhVEU1RcmbMsCFiWhbFsrDisaMMHy03GGjMUS2SZ6nkiC4Y/EvIx1p+tcLRsRxLdv 2Rtlpb8eNLIKH7dZLgMEuUAZEsIjGBReMp6WGOgTCczQSf0O62so7pSHZlHm9Zbo4F5k 7jDV+v7guJJoR+rZcBCufTi5QxOGzFh4PAEitu5uuTOlO7eVtRalERfvFeJN2K/Kxkqw FEHeJNO2zvDW+hfYKF2/xXG3YpCHna+BaNeTWBbhPc+ZE3AWOptiso6XOCpOZJzuLaxm 2Stg== X-Gm-Message-State: AAQBX9dhUdtRS9NOOz4x83FGlhOtMAJ9uTUs4A8rzWwygceHSiZpfCxA IbJxbLdnLRb8iNPgGho7hwkQKTvFMn9/EOasvvOBQpCyRkY= X-Google-Smtp-Source: AK7set/kO5YMp/4lBZ4dZN9e5nbK9j9USvsfow1FDtL5pMF514GHddrvlnMiF4x42xpHiDZTcaLqvOtyZSFEjXs/I80= X-Received: by 2002:a17:907:869f:b0:8b8:aef3:f2a9 with SMTP id qa31-20020a170907869f00b008b8aef3f2a9mr17074931ejc.0.1680536060013; Mon, 03 Apr 2023 08:34:20 -0700 (PDT) MIME-Version: 1.0 References: <20230403141105.551198-1-nisha.s.menon@gmail.com> In-Reply-To: <20230403141105.551198-1-nisha.s.menon@gmail.com> From: Noah Goldstein Date: Mon, 3 Apr 2023 10:34:08 -0500 Message-ID: Subject: Re: [PATCH] compare_strings.py : Add --gmean flag To: Nisha Poyarekar Cc: libc-alpha@sourceware.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Mon, Apr 3, 2023 at 9:11=E2=80=AFAM Nisha Poyarekar via Libc-alpha wrote: > > To calculate geometric mean for string benchmark results. > > Signed-off-by: Nisha Poyarekar > --- > benchtests/scripts/compare_strings.py | 20 ++++++++++++++++++-- > 1 file changed, 18 insertions(+), 2 deletions(-) > > diff --git a/benchtests/scripts/compare_strings.py b/benchtests/scripts/c= ompare_strings.py > index 1195a6c741..a4ab3e42c2 100755 > --- a/benchtests/scripts/compare_strings.py > +++ b/benchtests/scripts/compare_strings.py > @@ -21,6 +21,7 @@ Given a string benchmark result file, print a table wit= h comparisons with a > baseline. The baseline is the first function, which typically is the bu= iltin > function. > """ > +import math > import matplotlib as mpl > mpl.use('Agg') > > @@ -83,7 +84,8 @@ def draw_graph(f, v, ifuncs, results): > pylab.savefig('%s-%s.png' % (f, v), bbox_inches=3D'tight') > > > -def process_results(results, attrs, funcs, base_func, graph, no_diff, no= _header): > +def process_results(results, attrs, funcs, base_func, graph, no_diff, > + no_header, gmean): > """ Process results and print them > > Args: > @@ -132,6 +134,8 @@ def process_results(results, attrs, funcs, base_func,= graph, no_diff, no_header) > print("%36s%s" % (' ', '\t'.join(ifuncs))) > print("=3D" * 120) > > + mean_row =3D [0 for i in range(len(ifuncs))] > + total=3D0 > graph_res =3D {} > for res in results['functions'][f]['results']: > try: > @@ -144,8 +148,11 @@ def process_results(results, attrs, funcs, base_func= , graph, no_diff, no_header) > key =3D ', '.join(attr_list) > sys.stdout.write('%36s: ' % key) > graph_res[key] =3D res['timings'] > + > for t in res['timings']: > if selected[i]: > + if gmean: > + mean_row[i] =3D mean_row[i]+math.log(t) Is there an issue using statistics package and just doing: `statistics.geometric_mean` ? Otherwise LGTM. > sys.stdout.write ('%12.2f' % t) > if not no_diff: > if i !=3D base_index: > @@ -159,6 +166,12 @@ def process_results(results, attrs, funcs, base_func= , graph, no_diff, no_header) > if graph: > draw_graph(f, v, results['functions'][f]['ifuncs'], graph_re= s) > > + if gmean: > + print("=3D" * 120) > + total =3D len(results['functions'][f]['results']) > + sys.stdout.write ('Geo-mean (for %s inputs)'%total) > + for m in mean_row: > + sys.stdout.write ('%12.2f' % (math.exp(m/total))) > > def main(args): > """Program Entry Point > @@ -180,7 +193,8 @@ def main(args): > funcs =3D None > > results =3D parse_file(args.input, args.schema) > - process_results(results, attrs, funcs, base_func, args.graph, args.n= o_diff, args.no_header) > + process_results(results, attrs, funcs, base_func, args.graph, args.n= o_diff, > + args.no_header, args.gmean) > return os.EX_OK > > > @@ -207,6 +221,8 @@ if __name__ =3D=3D '__main__': > help=3D'Do not print the difference from baselin= e.') > parser.add_argument('--no-header', action=3D'store_true', > help=3D'Do not print the header.') > + parser.add_argument('--gmean', action=3D'store_true', > + help=3D'Print the geometric mean at the end of t= he output.') > > args =3D parser.parse_args() > sys.exit(main(args)) > -- > 2.37.2 >