File: _test_performance.py

package info (click to toggle)
python-yappi 1.6.10-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,612 kB
  • sloc: python: 4,081; ansic: 2,500; makefile: 27
file content (25 lines) | stat: -rw-r--r-- 528 bytes parent folder | download
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
import sys
import time
import yappi


def generate_func(code):
    func_name = f"func_{i}"
    code = f"""def {func_name}(*args, **kwargs): {code}"""
    exec(code, {}, locals())
    return locals()[func_name]


print("Generating functions...")

funcs = []
for i in range(int(sys.argv[1])):
    funcs.append(generate_func("pass"))

print("Calling functions...")
t0 = time.time()
yappi.start()
for _, func in enumerate(funcs):
    for i in range(int(sys.argv[2])):
        func(i)
print(f"Elapsed {time.time() - t0:0.6f} secs.")