Skip to content

Commit

Permalink
benchmark suite v1
Browse files Browse the repository at this point in the history
  • Loading branch information
viblo committed Jul 26, 2024
1 parent 1cb7cf0 commit eeb4974
Showing 1 changed file with 36 additions and 25 deletions.
61 changes: 36 additions & 25 deletions benchmarks/chipmunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,18 @@
import gc
import io
import math
import os

import pymunk

try:
import pygame

import pymunk.pygame_util

pymunk.pygame_util.positive_y_is_up = True
except:
pass
"""
Benchmarks
Expand Down Expand Up @@ -232,9 +241,6 @@ def __init__(self, size):
self.space.add(b, c)


import random


class Multifixture(Benchmark):
steps = 500
default_size = 100
Expand All @@ -244,7 +250,6 @@ class Multifixture(Benchmark):

def __init__(self, size):
super().__init__()
random.seed(1)
s1 = pymunk.Segment(self.space.static_body, (-35, 0), (35, 0), 1)
s2 = pymunk.Segment(self.space.static_body, (-36, 50), (-36, 0), 1)
s3 = pymunk.Segment(self.space.static_body, (36, 50), (36, 0), 1)
Expand Down Expand Up @@ -526,6 +531,20 @@ def __init__(self, size):
self.space.add(b, c)


class Stacking:

def __init__(self):
self.space = pymunk.Space()

s = pymunk.Segment(self.space.static_body, (0, 500), (500, 500), 5)

def update(self, dt):
pass

def draw(self):
pass


benchmarks = [
FallingSquares,
FallingCircles,
Expand Down Expand Up @@ -615,6 +634,18 @@ def run(bench_cls, size, interactive):
sim.update(1 / fps)
steps += 1

if not interactive and False: # temp disabled until end state is nice to look at.
try:
os.environ["SDL_VIDEODRIVER"] = "dummy"
surface = pygame.Surface((600, 600))
draw_options = pymunk.pygame_util.DrawOptions(surface)
draw_options.flags = draw_options.DRAW_SHAPES
surface.fill(pygame.Color("white"))
sim.draw(draw_options)
pygame.image.save(surface, f"{bench_cls.__name__}_{size}.png")
except Exception as e:
print("Could not save screenshot", e)

time_s = timeit.default_timer() - start_time
return {"benchmark": bench_cls.__name__, "size": size, "time": time_s}

Expand All @@ -629,7 +660,7 @@ def run(bench_cls, size, interactive):
choices=benchmark_names,
nargs="*",
help="Run these benchmarks",
default=benchmark_names[0:1],
default=benchmark_names,
)
parser.add_argument(
"-s",
Expand All @@ -650,12 +681,6 @@ def run(bench_cls, size, interactive):
writer = csv.DictWriter(csv_output, fieldnames=["benchmark", "size", "time"])
writer.writeheader()
for name in args.benchmarks:
if args.interactive:
import pygame

import pymunk.pygame_util

pymunk.pygame_util.positive_y_is_up = True

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

Expand All @@ -679,17 +704,3 @@ def run(bench_cls, size, interactive):
print("DONE!")
print("Full Result:")
print(csv_output.getvalue())


class Stacking:

def __init__(self):
self.space = pymunk.Space()

s = pymunk.Segment(self.space.static_body, (0, 500), (500, 500), 5)

def update(self, dt):
pass

def draw(self):
pass

0 comments on commit eeb4974

Please sign in to comment.