-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark_overhead.py
More file actions
48 lines (41 loc) · 1.25 KB
/
benchmark_overhead.py
File metadata and controls
48 lines (41 loc) · 1.25 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""
Benchmark to determine overhead sources:
1. Python startup time
2. Binding/data copy overhead
"""
import sys
import time
# Measure import time
import_start = time.perf_counter()
from rapidobj import parse_obj
import_elapsed = time.perf_counter() - import_start
if len(sys.argv) < 2:
print(f"Usage: {sys.argv[0]} <obj_path> [iterations]")
sys.exit(1)
obj_path = sys.argv[1]
iterations = int(sys.argv[2]) if len(sys.argv) > 2 else 5
print(f"Python import time: {import_elapsed*1000:.2f} ms")
print(f"Parsing: {obj_path}")
print(f"Iterations: {iterations}")
print("-" * 50)
times = []
ret = None
for i in range(iterations):
start = time.perf_counter()
ret = parse_obj(obj_path)
elapsed = time.perf_counter() - start
times.append(elapsed * 1000)
# Access the arrays to force any lazy evaluation
_ = ret.vertices.shape
_ = ret.faces.shape
_ = ret.texcoords.shape
_ = ret.wedge_texcoord_indices.shape
print(f"Parse times: {[f'{t:.2f}' for t in times]} ms")
print(f"Average: {sum(times)/len(times):.2f} ms")
print(f"Min: {min(times):.2f} ms")
print(f"Max: {max(times):.2f} ms")
print()
if ret is None:
raise RuntimeError("No iterations were run")
print(f"Vertices: {ret.vertices.shape}")
print(f"Faces: {ret.faces.shape}")