python计算程序运行时间


import time


def calculate_time(total_time):
    '''
    total_time: total seconds
    '''
    spend_seconds = total_time % 60
    totalminutes = total_time // 60
    spend_minutes = totalminutes % 60
    spend_hours = totalminutes // 60
    return spend_hours, spend_minutes, spend_seconds


def main():
    start_time = time.time()
    
   ‘’‘
   相关程序
   ’‘’
        
    end_time = time.time()
    total_time = end_time - start_time
    spend_hours, spend_minutes, spend_seconds = calculate_time(total_time)
    print 'Total running time of the example: %.2f seconds ( %i hours %i minutes %.2f seconds )' \
    % (total_time, spend_hours, spend_minutes, spend_seconds)
    
    
main()    

posted @ 2017-07-03 17:15  banlucainiao  阅读(29)  评论(0)    收藏  举报