Add function name to decorator output
<p>I have a python code snippet that allows me to time function as a decorator. I would like to add function name to the output. and time in milli-seconds </p>

<pre><code>def func_timer(func):
    def f(*args, **kwargs):
        start   = time.time()
        results = func(*args, **kwargs)
        print "Elapsed: %.6fs" % (time.time() - start)
        return results

    return f
</code></pre>

<p>Usage is: </p>

<pre><code>@func_timer
def foo():
    pass
</code></pre>

<p>Current Output is :</p>

<pre><code>Elapsed: 0.005168s
</code></pre>

<p>Output desired:</p>

<pre><code>foo Elapsed: 5.168ms
</code></pre>

<p>Function objects have a <code>__name__</code> attribute, you can use that. Simply multiply the time by 1000 if you want milliseconds:</p>

<pre><code>print "%s Elapsed: %.6fms" % (func.__name__, (time.time() - start) * 1000)
</code></pre>

python function decorator python-decorators