在我的打印语句中添加代码块的计时

2024-06-25 23:13:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我有下面的代码片段。我有print语句,所以它将在控制台窗口中打印当前正在处理的代码部分。我想知道是否有一种方法可以增加计算print语句中每个代码块所需的时间

print('Starting Backtest Instantiation')
backtester_example = Backtest(new_data_sample, position_logic_example)

print('Running Output DF')
aggstats = backtester_example.agg_stats()
stats_df = backtester_example.output_all_metrics_as_df()

print('Running Tabular Trades')

compact_data = backtester_example.tabular_trades()
print('FinishedTabularTrades')

Tags: 方法代码dfnewdataexamplestats时间