Python speed testing - Time Difference - milliseconds

后端 未结 13 1393
小蘑菇
小蘑菇 2020-11-27 10:41

What is the proper way to compare 2 times in Python in order to speed test a section of code? I tried reading the API docs. I\'m not sure I understand the timedelta thing.

13条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-27 10:57

    You could also use:

    import time
    
    start = time.clock()
    do_something()
    end = time.clock()
    print "%.2gs" % (end-start)
    

    Or you could use the python profilers.

提交回复
热议问题