forked from DataDog/dd-trace-py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.py
86 lines (66 loc) · 2.2 KB
/
benchmark.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import time
import timeit
from ddtrace import Tracer
from .test_tracer import DummyWriter
from os import getpid
REPEAT = 10
NUMBER = 10000
def trace_error(tracer):
# explicit vars
with tracer.trace("a", service="s", resource="r", span_type="t"):
1 / 0
def benchmark_tracer_trace():
tracer = Tracer()
tracer.writer = DummyWriter()
# testcase
def trace(tracer):
# explicit vars
with tracer.trace("a", service="s", resource="r", span_type="t") as s:
s.set_tag("a", "b")
s.set_tag("b", 1)
with tracer.trace("another.thing"):
pass
with tracer.trace("another.thing"):
pass
# benchmark
print("## tracer.trace() benchmark: {} loops ##".format(NUMBER))
timer = timeit.Timer(lambda: trace(tracer))
result = timer.repeat(repeat=REPEAT, number=NUMBER)
print("- trace execution time: {:8.6f}".format(min(result)))
def benchmark_tracer_wrap():
tracer = Tracer()
tracer.writer = DummyWriter()
# testcase
class Foo(object):
@staticmethod
@tracer.wrap()
def s():
return 0
@classmethod
@tracer.wrap()
def c(cls):
return 0
@tracer.wrap()
def m(self):
return 0
f = Foo()
# benchmark
print("## tracer.trace() wrapper benchmark: {} loops ##".format(NUMBER))
timer = timeit.Timer(f.s)
result = timer.repeat(repeat=REPEAT, number=NUMBER)
print("- staticmethod execution time: {:8.6f}".format(min(result)))
timer = timeit.Timer(f.c)
result = timer.repeat(repeat=REPEAT, number=NUMBER)
print("- classmethod execution time: {:8.6f}".format(min(result)))
timer = timeit.Timer(f.m)
result = timer.repeat(repeat=REPEAT, number=NUMBER)
print("- method execution time: {:8.6f}".format(min(result)))
def benchmark_getpid():
timer = timeit.Timer(getpid)
result = timer.repeat(repeat=REPEAT, number=NUMBER)
print("## getpid wrapper benchmark: {} loops ##".format(NUMBER))
print("- getpid execution time: {:8.6f}".format(min(result)))
if __name__ == '__main__':
benchmark_tracer_wrap()
benchmark_tracer_trace()
benchmark_getpid()