Created
July 1, 2012 02:46
-
-
Save eddyxu/3026599 to your computer and use it in GitHub Desktop.
Python benchmark decorator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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