-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinvestigate.py
More file actions
executable file
·34 lines (28 loc) · 1.04 KB
/
investigate.py
File metadata and controls
executable file
·34 lines (28 loc) · 1.04 KB
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
#!/usr/bin/env python
import pprint
import timeit
import calling # python3 setup.py build_ext --inplace --force
print("Calling convention for meth(1, 2, 3, four=4, five=5, six=6)")
for n in dir(calling):
if n.startswith("with_"):
v=getattr(calling, n)(1, 2, 3, four=4, five=5, six=6)
print(n)
pprint.pprint(v)
print("Duplicate keyword args")
for n in dir(calling):
if n.startswith("with_"):
print(n)
try:
v=getattr(calling, n)(1, 2, 3, four=4, five=5, **{"four": 6})
pprint.pprint(v)
except TypeError:
print(" TypeError")
print("Calling overhead method(1, 2, 3, four=4, five=5, six=6)")
for n in dir(calling):
if n.startswith("bench_"):
print(n)
t=timeit.Timer("method(1, 2, 3, four=4, five=5, six=6)", setup=f"method=getattr(calling, '{ n }')", globals={"calling": calling})
nloops, _ = t.autorange()
nloops *=5 # run for ~1 second
took=t.timeit(nloops)
print(f"{ 1e9 * took / nloops:.1f} nanoseconds per call")