Skip to content

Commit 7ac9948

Browse files
authored
Multiprocessing re-work for benchmark utility (#30)
1 parent f66c95c commit 7ac9948

6 files changed

Lines changed: 30 additions & 32 deletions

File tree

benchmark/__main__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import multiprocessing
12
import argparse
23
import sys
34
from datetime import datetime
@@ -39,4 +40,5 @@ def parse_args(args):
3940

4041

4142
if __name__ == "__main__":
43+
multiprocessing.set_start_method("spawn")
4244
main()

benchmark/manager.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ def create_test_instances(self):
9090
# If a test have multiple instances, create one instance for each
9191
if cls.instances:
9292
for params, _ in cls.instances:
93-
self.add_test_instance(cls(**params))
93+
self.add_test_instance(cls(self.session_dir, **params))
9494
else:
95-
self.add_test_instance(cls())
95+
self.add_test_instance(cls(self.session_dir))
9696

9797
if self.debug:
9898
num_instances = len(self.test_instances)
@@ -120,7 +120,8 @@ def get_test_instance(self, name: str) -> Optional[PerfTest]:
120120
def run(self):
121121
"""Run all tests"""
122122
for instance in self.test_instances:
123-
instance.run(self.session_dir)
123+
instance.start()
124+
instance.join()
124125

125126
def create_graph(
126127
self,

benchmark/tests/arcade/collision.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import random
2+
from pathlib import Path
23

34
import arcade
45

@@ -20,8 +21,9 @@ class Test(ArcadePerfTest):
2021
name = "collision"
2122
instances = (({"method": 3}, "Simple"),)
2223

23-
def __init__(self, method: int = DEFAULT_METHOD):
24+
def __init__(self, session_dir: Path, method: int = DEFAULT_METHOD):
2425
super().__init__(
26+
session_dir,
2527
size=(SCREEN_WIDTH, SCREEN_HEIGHT),
2628
title=SCREEN_TITLE,
2729
start_count=0,

benchmark/tests/arcade_accelerate/collision.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import random
2+
from pathlib import Path
3+
4+
import arcade_accelerate
5+
arcade_accelerate.bootstrap()
26

37
import arcade
48

@@ -20,8 +24,9 @@ class Test(AcceleratedPerfTest):
2024
name = "collision"
2125
instances = (({"method": 3}, "Simple"),)
2226

23-
def __init__(self, method: int = DEFAULT_METHOD):
27+
def __init__(self, session_dir: Path, method: int = DEFAULT_METHOD):
2428
super().__init__(
29+
session_dir,
2530
size=(SCREEN_WIDTH, SCREEN_HEIGHT),
2631
title=SCREEN_TITLE,
2732
start_count=0,

benchmark/tests/base.py

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
import sys
1+
import multiprocessing
22
from pathlib import Path
33
from typing import Tuple
44

5-
import arcade
6-
75
from benchmark.timing import PerformanceTiming
86

97

10-
class PerfTest:
8+
class PerfTest(multiprocessing.Process):
119
name = "default"
1210
type = "default"
1311
series_name = "default"
1412
instances = []
1513

1614
def __init__(
1715
self,
16+
session_dir: Path,
1817
size: Tuple[int, int],
1918
title: str = "Perf Test",
2019
start_count: int = 0,
2120
increment_count: int = 100,
2221
duration: float = 60.0,
2322
**kwargs,
2423
):
24+
super().__init__()
25+
self.session_dir = session_dir
2526
self.size = size
2627
self.title = title
2728
self.start_count = start_count
@@ -43,9 +44,9 @@ def on_update(self, delta_time: float):
4344
def update_state(self):
4445
pass
4546

46-
def run(self, session_dir: Path):
47+
def run(self):
4748
self.frame = 0
48-
out_path = session_dir / "data"
49+
out_path = self.session_dir / "data"
4950
out_path.mkdir(parents=True, exist_ok=True)
5051

5152
self.timing = PerformanceTiming(
@@ -61,6 +62,7 @@ class ArcadePerfTest(PerfTest):
6162

6263
def __init__(
6364
self,
65+
session_dir: Path,
6466
size: Tuple[int, int],
6567
title: str = "Perf Test",
6668
start_count: int = 0,
@@ -69,6 +71,7 @@ def __init__(
6971
**kwargs,
7072
):
7173
super().__init__(
74+
session_dir,
7275
size=size,
7376
title=title,
7477
start_count=start_count,
@@ -99,9 +102,9 @@ def run_test(self):
99102
self.update_state()
100103
self.window.flip()
101104

102-
def run(self, session_dir: Path):
105+
def run(self):
103106
"""Run the test collecting data."""
104-
super().run(session_dir)
107+
super().run()
105108
self.create_window()
106109
self.setup()
107110

@@ -129,6 +132,7 @@ def run(self, session_dir: Path):
129132
self.timing.write()
130133

131134
def create_window(self):
135+
import arcade
132136
try:
133137
self.window = arcade.get_window()
134138
self.window.set_size(*self.size)
@@ -142,22 +146,4 @@ def create_window(self):
142146

143147

144148
class AcceleratedPerfTest(ArcadePerfTest):
145-
type = "arcade-accelerate"
146-
147-
def run(self, session_dir: Path):
148-
# This is necessary to unload arcade and ensure that we have the arcade-accelerate bootstrap applied
149-
# The test module itself is responsbile for applying the bootstrap, but arcade needs to be fully unloaded before then
150-
to_uncache = []
151-
for mod in sys.modules:
152-
if mod.startswith("arcade."):
153-
to_uncache.append(mod)
154-
155-
for mod in to_uncache:
156-
del sys.modules[mod]
157-
158-
import arcade_accelerate
159-
160-
arcade_accelerate.bootstrap()
161-
import arcade
162-
163-
super().run(session_dir)
149+
type = "accelerate"

src/sprite_list.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ pub fn check_for_collision_with_list(
77
py: Python<'_>,
88
sprite: &PyAny, //
99
sprite_list: &PyAny,
10+
method: Option<i32>,
1011
) -> Vec<PyObject> {
12+
let _final_method = method.unwrap_or(3);
1113
let mut final_sprites: Vec<PyObject> = Vec::new();
1214

1315
let mut hitbox1: Option<HitBox> = None;

0 commit comments

Comments
 (0)