From adbb5d4e5961c4aedaa8c469894e3977b8b4e141 Mon Sep 17 00:00:00 2001 From: "martin.holmer@gmail.com" Date: Mon, 27 May 2024 18:37:08 -0400 Subject: [PATCH] Add CLI tc --timings option --- taxcalc/cli/tc.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/taxcalc/cli/tc.py b/taxcalc/cli/tc.py index 66873f3e6..764564fbc 100644 --- a/taxcalc/cli/tc.py +++ b/taxcalc/cli/tc.py @@ -8,6 +8,7 @@ import os import sys +import time import argparse import difflib import taxcalc as tc @@ -29,7 +30,7 @@ def cli_tc_main(): (' ' '[--baseline BASELINE] [--reform REFORM] [--assump ASSUMP]\n'), (' ' - '[--exact] [--tables] [--graphs]\n'), + '[--exact] [--tables] [--graphs] [--timings]\n'), (' ' '[--dump] [--dvars DVARS] [--sqldb] [--outdir OUTDIR]\n'), (' ' @@ -88,6 +89,11 @@ def cli_tc_main(): 'to HTML files for viewing in browser.'), default=False, action="store_true") + parser.add_argument('--timings', + help=('optional flag that causes execution times to ' + 'be written to stdout.'), + default=False, + action="store_true") parser.add_argument('--dump', help=('optional flag that causes OUTPUT to contain ' 'all INPUT variables (extrapolated to TAXYEAR) ' @@ -158,11 +164,16 @@ def cli_tc_main(): inputfn.endswith('cps.csv') or inputfn.endswith('tmd.csv') ) + if args.timings: + stime = time.time() tcio.init(input_data=inputfn, tax_year=taxyear, baseline=args.baseline, reform=args.reform, assump=args.assump, aging_input_data=aging, exact_calculations=args.exact) + if args.timings: + xtime = time.time() - stime + sys.stdout.write(f'TIMINGS: init time = {xtime:.2f} secs\n') if tcio.errmsg: sys.stderr.write(tcio.errmsg) sys.stderr.write('USAGE: tc --help\n') @@ -183,12 +194,17 @@ def cli_tc_main(): sys.stderr.write('USAGE: tc --help\n') return 1 # conduct tax analysis + if args.timings: + stime = time.time() tcio.analyze(writing_output_file=True, output_tables=args.tables, output_graphs=args.graphs, dump_varset=dumpvar_set, output_dump=args.dump, output_sqldb=args.sqldb) + if args.timings: + xtime = time.time() - stime + sys.stdout.write(f'TIMINGS: calc time = {xtime:.2f} secs\n') # compare test output with expected test output if --test option specified if args.test: retcode = _compare_test_output_files()