美文网首页
python 计算程序运行的时间

python 计算程序运行的时间

作者: 逍遥_yjz | 来源:发表于2018-12-20 16:53 被阅读0次
    import datetime
    
    
    starttime = datetime.datetime.now()
    
    for i in range(1,10000000):
        print("Python计算程序运行时间")
    # long running
    endtime = datetime.datetime.now()
    
    seconds = (endtime - starttime).seconds
    start = starttime.strftime('%Y-%m-%d %H:%M')
    # 100 秒
    # 分钟
    minutes = seconds // 60
    second = seconds % 60
    print((endtime - starttime))
    timeStr = str(minutes) + '分钟' + str(second) + "秒"
    print("程序从 " + start + ' 开始运行,运行时间为:' + timeStr)
    
    

    输出:

    .......................
    .......................
    Python计算程序运行时间
    0:00:45.941982
    程序从 2018-12-20 16:50 开始运行,运行时间为:0分钟45秒
    

    参考资料:https://www.cnblogs.com/rookie-c/p/5827694.html
    定时

    相关文章

      网友评论

          本文标题:python 计算程序运行的时间

          本文链接:https://www.haomeiwen.com/subject/gwtukqtx.html