Skip to content

Instantly share code, notes, and snippets.

@eddyxu
Created July 1, 2012 02:46
Show Gist options
  • Save eddyxu/3026599 to your computer and use it in GitHub Desktop.
Save eddyxu/3026599 to your computer and use it in GitHub Desktop.
Python benchmark decorator
class benchmark(object):
"""Run a function as benchmark for several times.
Usage:
>>> @benchmark(times=1) # times is a optional parameter.
>>> def awesome_benchmark(arg1, arg2):
>>> # do awesome benchmarks.
"""
def __init__(self, **kwargs):
self.times = kwargs.get('times', 1)
def __call__(self, func):
def benchmark_func(*args):
for i in range(self.times):
func(*args)
return benchmark_func
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment