Skip to content

Commit

Permalink
Wip on benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
viblo committed Dec 27, 2024
1 parent b7b52cd commit 57b99be
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions benchmarks/chipmunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,6 @@

import pymunk

try:
import pygame

import pymunk.pygame_util

pymunk.pygame_util.positive_y_is_up = True
except:
pass


class Benchmark:
steps = 500
Expand Down Expand Up @@ -176,7 +167,7 @@ def update(self, dt):


class AddPair(Benchmark):
steps = 1000
steps = 3000
default_size = 2000
size_start = 100
size_end = 2500
Expand Down Expand Up @@ -614,6 +605,12 @@ def run(bench_cls, size, interactive):
sim_start_time = timeit.default_timer()

if interactive:
import pygame

import pymunk.pygame_util

pymunk.pygame_util.positive_y_is_up = True

clock = pygame.time.Clock()
screen = pygame.display.set_mode((600, 600))
draw_options = pymunk.pygame_util.DrawOptions(screen)
Expand Down Expand Up @@ -671,7 +668,7 @@ def run(bench_cls, size, interactive):
f"step {steps} fps {clock.get_fps():.2f} total {timeit.default_timer()-sim_start_time:.2f}s"
)

sim.update(1 / fps)
sim.update(1 / fps / 50)
steps += 1

if not interactive and False: # temp disabled until end state is nice to look at.
Expand Down Expand Up @@ -710,7 +707,8 @@ def run(bench_cls, size, interactive):
"-s",
"--size",
type=int,
help="Size of simulation (e.g. number of items). Set to -1 to iterate the sizes",
help="""Size of simulation (e.g. number of items). If not set uses a default size.
Set to -1 to iterate the sizes""",
)
parser.add_argument(
"-i",
Expand All @@ -723,7 +721,7 @@ def run(bench_cls, size, interactive):

csv_output = io.StringIO()
writer = csv.DictWriter(
csv_output, fieldnames=["benchmark", "size", "init_time", "run_time"]
csv_output, fieldnames=["version", "benchmark", "size", "init_time", "run_time"]
)
writer.writeheader()
for name in args.benchmarks:
Expand All @@ -750,6 +748,7 @@ def run(bench_cls, size, interactive):

res = run(bench_cls, size, args.interactive)
print(res)
res["version"] = pymunk.version
writer.writerow(res)
print("DONE!")
print("Full Result:")
Expand Down

0 comments on commit 57b99be

Please sign in to comment.