Is there any simple way to benchmark python script?

前端 未结 10 773
借酒劲吻你
借酒劲吻你 2020-11-28 00:53

Usually I use shell command time. My purpose is to test if data is small, medium, large or very large set, how much time and memory usage will be.

Any t

10条回答
  •  佛祖请我去吃肉
    2020-11-28 01:25

    I use a simple decorator to time the func

    def st_time(func):
        """
            st decorator to calculate the total time of a func
        """
    
        def st_func(*args, **keyArgs):
            t1 = time.time()
            r = func(*args, **keyArgs)
            t2 = time.time()
            print "Function=%s, Time=%s" % (func.__name__, t2 - t1)
            return r
    
        return st_func
    

提交回复
热议问题