Files
owniverse/tests/benchmark_ui_speed6.gd
T
Kirill c4e7302567 Add new tests and implement frame budget management
- Introduced `civilization_benchmark.gd` and `legacy_quantity_math.gd` for benchmarking and legacy quantity calculations.
- Created `test_dynamic_math.gd`, `test_frame_evolution.gd`, and `test_sparse_batches.gd` to validate mathematical operations and frame evolution logic.
- Implemented `frame_budget.gd` to manage cooperative work on the main thread, ensuring no partially calculated state is published.
- Added UID files for all new scripts to maintain unique identifiers.
2026-10-01 23:43:34 +03:00

57 lines
2.9 KiB
GDScript

extends SceneTree
const E = preload("res://world/owniverse/math/exact.gd")
func _initialize(): call_deferred("run")
func report(label: String, samples: Array):
var total: float = 0.0
var slow: int = 0
for sample in samples:
total += sample
if sample > 33.333: slow += 1
samples.sort()
print("%s: %d samples, mean %.3f ms, p95 %.3f ms, max %.3f ms, >33ms %d" % [label, samples.size(), total / samples.size(), samples[int(samples.size() * 0.95) - 1], samples.back(), slow])
func run():
Engine.max_fps = 60
DisplayServer.window_set_size(Vector2i(540, 960))
print("Renderer: ", RenderingServer.get_current_rendering_method(), " adapter: ", RenderingServer.get_video_adapter_name())
for scenario in ["ordinary", "hypergiants"]:
for page in ([2] if "stars" in OS.get_cmdline_user_args() else [1, 2]):
var scene = load("res://world/world.tscn").instantiate()
var stage = scene.get_node("Stage")
stage.owniverse.free()
stage.set_script(load("res://tests/fixtures/benchmark_ui_stage.gd"))
root.add_child(scene)
await process_frame
await process_frame
var world = stage.owniverse
world.speed = 6
world.state.amount.S = E.of("1e24")
world.state.amount.H = E.of("1e24")
for entry in [["RD", 1234567], ["YD", 765432], ["STN", 654321]]:
world.state.amount[entry[0]] = entry[1]
world.batches.append_batch(world.state, entry[0], entry[1], 0, 0)
if scenario == "hypergiants":
world.state.amount.HG = E.of("1e20")
world.batches.append_batch(world.state, "HG", E.of("1e20"), 0, 0)
var start_year = E.subtract(world.catalog.entities.HG.lifespan, 1000)
world.state.time = {"datetime": start_year, "year": start_year}
stage.stage_page_scroller.scroll_horizontal = page * stage.PAGE_WIDTH
for item in stage.owniverse_items.values(): item.visible = true
if page == 2: stage._control_page(stage.owniverse_items.HG)
stage._set_item_description(stage.owniverse_items.HG if page == 2 else stage.owniverse_items.H)
stage._refresh_universe_ui()
for warmup in 30: await process_frame
stage.measuring = true
for frame in 600: await process_frame
stage.measuring = false
var label: String = "%s page %d" % [scenario, page]
report(label + " Stage CPU", stage.process_samples)
report(label + " frame wall", stage.frame_samples)
print("UI counters: H=", stage.owniverse_items.H.description.text, " HG=", stage.owniverse_items.HG.description.text, " date=", stage.date_time.text)
for entity in world.catalog.entities.values(): entity.free()
world.free()
scene.free()
quit()