rinkplanner/rinkplanner/tests/run_perf_tests.gd
torsten d44a4e1e2f feat: Tablet- und Web-Bedienung härten
- Oberfläche in CSS-Pixeln layouten (stretch disabled,
  content_scale_factor = Bildschirm-Skalierung), damit 56-px-Ziele auf
  Tablets auch 56 CSS-Pixel groß sind
- Kompakte Werkzeugleiste unter 1280 px, umbruchfähige Timing-Leiste;
  1024 px (iPad-Landscape) und 1400 px (Tab S9+) geprüft
- Chrome-Guard gegen synthetische Maus-Events vor/nach Touch-Gesten
- Web-Export-Preset und tools/export_web.sh (single-threaded)
- Kurven-Cache und Linien-Fastpath: Stresstest mit 480 Segmenten von
  ca. 48 ms auf ca. 7-10 ms pro Redraw
- Neue Suiten für Touch/Layout und Performance, Tablet-Testanleitung in
  docs/web-test.md
2026-10-30 09:37:14 +01:00

133 lines
3.8 KiB
GDScript

extends SceneTree
## Performance stress test for the whiteboard canvas.
##
## Builds many sections and segments, then measures the cost of a forced
## redraw. The bound is deliberately generous so the test stays useful on
## slow machines; the goal is to catch accidental super-linear behaviour,
## not to benchmark exact frame times.
const WhiteboardScene := preload("res://scenes/whiteboard/whiteboard.tscn")
const EXTRA_SECTIONS := 11
const SEGMENTS_PER_SECTION := 40
const MAX_AVG_DRAW_MS := 120.0
var _assertions: int = 0
var _failures: PackedStringArray = PackedStringArray()
func _init() -> void:
_run.call_deferred()
func _run() -> void:
var scene := WhiteboardScene.instantiate()
var controller := scene as WhiteboardController
if controller == null:
printerr("FAIL: scene is not a WhiteboardController")
quit(1)
return
controller.restore_autosave = false
controller.autosave_enabled = false
root.add_child(scene)
await process_frame
await process_frame
var canvas := controller.rink_canvas
var routine := controller.get_routine()
_fill_section(controller.get_active_section(), 0)
for index: int in range(1, EXTRA_SECTIONS + 1):
_fill_section(controller.add_section(), index)
var expected := (EXTRA_SECTIONS + 1) * SEGMENTS_PER_SECTION
var total_segments := 0
for section: RoutineSection in routine.sections:
total_segments += section.segments.size()
_check(
total_segments == expected,
"stress routine has %d segments (got %d)" % [expected, total_segments]
)
canvas.fit_rink()
canvas.refresh()
await process_frame
# Warm up font/theme caches before measuring.
for _index: int in range(3):
canvas.refresh()
await process_frame
var samples: PackedFloat64Array = PackedFloat64Array()
for _index: int in range(20):
var started := Time.get_ticks_usec()
canvas.refresh()
await process_frame
samples.append(float(Time.get_ticks_usec() - started) / 1000.0)
var total := 0.0
for sample: float in samples:
total += sample
var average := total / float(samples.size())
print(
"Perf: %d segments in %d sections, average redraw %.2f ms"
% [total_segments, routine.sections.size(), average]
)
_check(
average < MAX_AVG_DRAW_MS,
"average redraw stays below %.0f ms (got %.2f ms)"
% [MAX_AVG_DRAW_MS, average]
)
scene.queue_free()
await process_frame
_finish()
func _fill_section(section: RoutineSection, lane_offset: int) -> void:
var rink := RinkDimensions.new()
var lane_count := maxi(1, SEGMENTS_PER_SECTION)
var usable := rink.get_half_width() * 2.0 - 4.0
for index: int in range(lane_count):
var y := -rink.get_half_width() + 2.0 + usable * float(index) / float(lane_count)
y += float(lane_offset) * 0.05
var start := Vector2(-rink.get_half_length() + 6.0, y)
var end := Vector2(rink.get_half_length() - 6.0, y + 0.2)
var segment := PathSegment.new()
segment.segment_id = "perf-%d-%d" % [lane_offset, index]
segment.curve = Curve2D.new()
if index % 3 == 0:
segment.template = PathSegment.Template.ARC
segment.arc_bulge_left = index % 2 == 0
segment.arc_depth_ratio = 0.12
var points := ArcGeometry.build_points(
start, end, segment.arc_bulge_left, segment.arc_depth_ratio, rink
)
for point: Vector2 in points:
segment.curve.add_point(point)
else:
segment.template = PathSegment.Template.LINE
segment.curve.add_point(start)
segment.curve.add_point(end)
segment.direction = (
PathSegment.Direction.BACKWARD if index % 5 == 0
else PathSegment.Direction.FORWARD
)
section.segments.append(segment)
func _check(condition: bool, message: String) -> void:
_assertions += 1
if not condition:
_failures.append(message)
func _finish() -> void:
if _failures.is_empty():
print("PASS: %d assertions" % _assertions)
quit(0)
return
for failure: String in _failures:
printerr("FAIL: %s" % failure)
printerr("%d of %d assertions failed" % [_failures.size(), _assertions])
quit(1)