Skip to content

Commit

Permalink
Merge pull request #2751 from martinholmer/add-tc-timings
Browse files Browse the repository at this point in the history
Add CLI tc --timings option
  • Loading branch information
martinholmer authored May 28, 2024
2 parents 7b9df55 + adbb5d4 commit e0234b6
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion taxcalc/cli/tc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import os
import sys
import time
import argparse
import difflib
import taxcalc as tc
Expand All @@ -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'),
(' '
Expand Down Expand Up @@ -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) '
Expand Down Expand Up @@ -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')
Expand All @@ -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()
Expand Down

0 comments on commit e0234b6

Please sign in to comment.