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

后端 未结 30 2365
甜味超标
甜味超标 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条回答
  •  忘掉有多难
    2020-11-22 02:41

    First, install humanfriendly package by opening Command Prompt (CMD) as administrator and type there - pip install humanfriendly

    Code:

    from humanfriendly import format_timespan
    import time
    begin_time = time.time()
    # Put your code here
    end_time = time.time() - begin_time
    print("Total execution time: ", format_timespan(end_time))
    

    Output:

提交回复
热议问题