Skip to content

Commit eeb4974

Browse files
committed
benchmark suite v1
1 parent 1cb7cf0 commit eeb4974

File tree

1 file changed

+36
-25
lines changed

1 file changed

+36
-25
lines changed

benchmarks/chipmunk.py

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,18 @@
33
import gc
44
import io
55
import math
6+
import os
67

78
import pymunk
89

10+
try:
11+
import pygame
12+
13+
import pymunk.pygame_util
14+
15+
pymunk.pygame_util.positive_y_is_up = True
16+
except:
17+
pass
918
"""
1019
Benchmarks
1120
@@ -232,9 +241,6 @@ def __init__(self, size):
232241
self.space.add(b, c)
233242

234243

235-
import random
236-
237-
238244
class Multifixture(Benchmark):
239245
steps = 500
240246
default_size = 100
@@ -244,7 +250,6 @@ class Multifixture(Benchmark):
244250

245251
def __init__(self, size):
246252
super().__init__()
247-
random.seed(1)
248253
s1 = pymunk.Segment(self.space.static_body, (-35, 0), (35, 0), 1)
249254
s2 = pymunk.Segment(self.space.static_body, (-36, 50), (-36, 0), 1)
250255
s3 = pymunk.Segment(self.space.static_body, (36, 50), (36, 0), 1)
@@ -526,6 +531,20 @@ def __init__(self, size):
526531
self.space.add(b, c)
527532

528533

534+
class Stacking:
535+
536+
def __init__(self):
537+
self.space = pymunk.Space()
538+
539+
s = pymunk.Segment(self.space.static_body, (0, 500), (500, 500), 5)
540+
541+
def update(self, dt):
542+
pass
543+
544+
def draw(self):
545+
pass
546+
547+
529548
benchmarks = [
530549
FallingSquares,
531550
FallingCircles,
@@ -615,6 +634,18 @@ def run(bench_cls, size, interactive):
615634
sim.update(1 / fps)
616635
steps += 1
617636

637+
if not interactive and False: # temp disabled until end state is nice to look at.
638+
try:
639+
os.environ["SDL_VIDEODRIVER"] = "dummy"
640+
surface = pygame.Surface((600, 600))
641+
draw_options = pymunk.pygame_util.DrawOptions(surface)
642+
draw_options.flags = draw_options.DRAW_SHAPES
643+
surface.fill(pygame.Color("white"))
644+
sim.draw(draw_options)
645+
pygame.image.save(surface, f"{bench_cls.__name__}_{size}.png")
646+
except Exception as e:
647+
print("Could not save screenshot", e)
648+
618649
time_s = timeit.default_timer() - start_time
619650
return {"benchmark": bench_cls.__name__, "size": size, "time": time_s}
620651

@@ -629,7 +660,7 @@ def run(bench_cls, size, interactive):
629660
choices=benchmark_names,
630661
nargs="*",
631662
help="Run these benchmarks",
632-
default=benchmark_names[0:1],
663+
default=benchmark_names,
633664
)
634665
parser.add_argument(
635666
"-s",
@@ -650,12 +681,6 @@ def run(bench_cls, size, interactive):
650681
writer = csv.DictWriter(csv_output, fieldnames=["benchmark", "size", "time"])
651682
writer.writeheader()
652683
for name in args.benchmarks:
653-
if args.interactive:
654-
import pygame
655-
656-
import pymunk.pygame_util
657-
658-
pymunk.pygame_util.positive_y_is_up = True
659684

660685
bench_cls = [bench for bench in benchmarks if bench.__name__ == name][0]
661686

@@ -679,17 +704,3 @@ def run(bench_cls, size, interactive):
679704
print("DONE!")
680705
print("Full Result:")
681706
print(csv_output.getvalue())
682-
683-
684-
class Stacking:
685-
686-
def __init__(self):
687-
self.space = pymunk.Space()
688-
689-
s = pymunk.Segment(self.space.static_body, (0, 500), (500, 500), 5)
690-
691-
def update(self, dt):
692-
pass
693-
694-
def draw(self):
695-
pass

0 commit comments

Comments
 (0)