-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify_accelerator.py
More file actions
51 lines (39 loc) · 1.29 KB
/
verify_accelerator.py
File metadata and controls
51 lines (39 loc) · 1.29 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
49
50
import sys
import os
import time
# Add the project root to sys.path so we can import spacehoarder
sys.path.append(os.getcwd())
try:
import treemap_accelerator as accelerator
from spacehoarder import models
except ImportError:
# If running from inside spacehoarder dir, adjust imports
sys.path.append(os.path.dirname(os.getcwd()))
import treemap_accelerator as accelerator
from spacehoarder import models
print("Imports successful!")
# Create a mock file tree
root = models.DirModel("/", depth=0, size=1000)
child1 = models.FileModel("/foo", 400, 1)
child2 = models.FileModel("/bar", 600, 1)
root.contains = [child1, child2]
# Measure Python+Rust Call
start = time.time()
print("Calling accelerator...")
width = 800.0
height = 600.0
min_size = 3.0
pad = 1.0
# Direct call to verify the Rust module
# Pass num_colors=5 arbitrarily
rects = accelerator.calculate_layout(root, width, height, min_size, pad, 5)
print(f"Rust returned {len(rects)} rectangles.")
end = time.time()
print(f"Time taken: {(end-start)*1000:.4f} ms")
# Verification
for r in rects:
print(f"Rect: x={r.x}, y={r.y}, w={r.w}, h={r.h}, name={r.name}, color={r.color_index}")
if len(rects) == 3:
print("SUCCESS: Got 3 rectangles (Root, Child1, Child2)")
else:
print("FAILURE: Incorrect number of rectangles")