Jack
Jack

Reputation: 3

How do you have python scripts display how much time it takes to execute each process?

It was something like cMessage I think? I can't remember, could someone help me?

Upvotes: 0

Views: 281

Answers (1)

user180100
user180100

Reputation:

cProfile ?

To time a function, you can also use a decorator like this one:

from functools import wraps
import time

def timed(f):
    """Time a function."""
    @wraps(f)
    def wrapper(*args, **kwds):
        start = time.clock()
        result = f(*args)
        end = 1000 * (time.clock() - start)
        print '%s: %.3f ms' % (f.func_name, end)
        return result
    return wrapper

And "mark" your fonction by "@timed" like that:

@timed
def toBeTimed():
    pass

Upvotes: 2

Related Questions