def cal_train_time(log_dicts, args):
    """Compute the average time per training iteration."""
    for i, log_dict in enumerate(log_dicts):
        print(f'{"-" * 5}Analyze train time of {args.json_logs[i]}{"-" * 5}')
        train_logs = log_dict['train']

        if 'epoch' in train_logs[0]:
            epoch_ave_times = []
            for _, logs in groupby(train_logs, lambda log: log['epoch']):
                if args.include_outliers:
                    all_time = np.array([log['time'] for log in logs])
                else:
                    all_time = np.array([log['time'] for log in logs])[1:]
                epoch_ave_times.append(all_time.mean())
            epoch_ave_times = np.array(epoch_ave_times)
            slowest_epoch = epoch_ave_times.argmax()
            fastest_epoch = epoch_ave_times.argmin()
            std_over_epoch = epoch_ave_times.std()
            print(f'slowest epoch {slowest_epoch + 1}, '
                  f'average time is {epoch_ave_times[slowest_epoch]:.4f}')
            print(f'fastest epoch {fastest_epoch + 1}, '
                  f'average time is {epoch_ave_times[fastest_epoch]:.4f}')
            print(f'time std over epochs is {std_over_epoch:.4f}')

        avg_iter_time = np.array([log['time'] for log in train_logs]).mean()
        print(f'average iter time: {avg_iter_time:.4f} s/iter')
        print()
Compute the average time per training iteration.
tools/analysis_tools/analyze_logs.py