How do I get time of a Python program's execution?

后端 未结 30 2351
甜味超标
甜味超标 2020-11-22 02:20

I have a command line program in Python that takes a while to finish. I want to know the exact time it takes to finish running.

I\'ve looked at the timeit

30条回答
  •  猫巷女王i
    2020-11-22 02:39

    The simplest way in Python:

    import time
    start_time = time.time()
    main()
    print("--- %s seconds ---" % (time.time() - start_time))
    

    This assumes that your program takes at least a tenth of second to run.

    Prints:

    --- 0.764891862869 seconds ---
    

提交回复
热议问题