您的位置:首页 > 编程语言 > Python开发

python计算程序运行时间

2017-07-03 17:15 721 查看
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()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: