forked from zodb/perfmetrics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
speedtest.py
37 lines (25 loc) · 824 Bytes
/
speedtest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from perfmetrics import metric
from perfmetrics import set_statsd_client
from timeit import timeit
@metric
def func_with_metric():
pass
def func_without_metric():
pass
def main():
t = timeit('f()', 'from __main__ import func_without_metric as f',
number=1000)
print('%f' % t)
t = timeit('f()', 'from __main__ import func_with_metric as f',
number=1000)
print('%f' % t)
set_statsd_client('statsd://localhost:8125')
t = timeit('f()', 'from __main__ import func_with_metric as f',
number=1000)
print('%f' % t)
from cProfile import runctx
d = {'_range': range(10000), 'func_with_metric': func_with_metric}
result = runctx('for _ in _range: func_with_metric()', d, d)
print(result)
if __name__ == '__main__':
main()