• 技术文章 >常见问题 >Python常见问题

    python如何获取程序执行时间?

    yangyang2020-05-22 13:37:53原创7460

    python获取程序执行时间的方法:

    1、使用time.clock()方法获取程序执行时间

    注:python的标准库手册推荐在任何情况下尽量使用time.clock().

    使用方法:

    1

    2

    3

    4

    5

    import time

    start =time.clock()

    #中间写上代码块

    end = time.clock()

    print('Running time: %s Seconds'%(end-start))

    2、使用time.time()方法计算

    1

    2

    3

    4

    5

    import time

    start=time.time()

    #中间写上代码块

    end=time.time()

    print('Running time: %s Seconds'%(end-start))

    3、使用datetime.datetime.now()方法获取

    1

    2

    3

    4

    5

    import datetime

    start=datetime.datetime.now()

    #中间写代码块

    end=datetime.datetime.now()

    print('Running time: %s Seconds'%(end-start))

    更多Python知识请关注Python自学网

    专题推荐:python
    上一篇:python如何下载网页? 下一篇:python怎么去掉日期中的横杠?

    相关文章推荐

    • python中怎么将pdf内容显示出来?• Python中猴子补丁是什么?

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网