fad862d618
- Introduced `benchmark_saved_state.gd` to evaluate the performance of the saved state restoration process. - Implemented JSON integer restoration to handle large integers accurately. - Added command-line argument parsing for specifying the path to the diagnostic JSON file and optional delta seconds. - Conducted performance tests at different speeds and logged the elapsed time for six consecutive steps. - Created a new UID file for the benchmark script.
48 lines
1.9 KiB
GDScript
48 lines
1.9 KiB
GDScript
extends SceneTree
|
|
## Read-only benchmark. Loads a diagnostic JSON, never invokes SaveManager.
|
|
const E = preload("res://world/owniverse/math/exact.gd")
|
|
|
|
func _initialize():
|
|
call_deferred("run")
|
|
|
|
func restore_json_integers(value):
|
|
# JSON parses ordinary integer tokens as float. Large integers are $exact.
|
|
if value is float and value == floorf(value) and absf(value) <= 9007199254740991:
|
|
return int(value)
|
|
if value is Dictionary:
|
|
for key in value: value[key] = restore_json_integers(value[key])
|
|
elif value is Array:
|
|
for i in value.size(): value[i] = restore_json_integers(value[i])
|
|
return value
|
|
|
|
func run():
|
|
var args = OS.get_cmdline_user_args()
|
|
if args.is_empty():
|
|
print("Usage: --script tests/benchmark_saved_state.gd -- /path/to/save.adventure.json [delta_seconds]")
|
|
quit(1)
|
|
return
|
|
var data = JSON.parse_string(FileAccess.get_file_as_string(args[0]))
|
|
if not data is Dictionary or data.get("format_version") != 3:
|
|
push_error("Expected diagnostic JSON format 3")
|
|
quit(1)
|
|
return
|
|
var initial: Dictionary = E.decode(restore_json_integers(data)).state
|
|
var delta: float = args[1].to_float() if args.size() > 1 else 1.0 / 60.0
|
|
if not is_finite(delta) or delta <= 0:
|
|
quit(1)
|
|
return
|
|
for speed in [1, 4, 6]:
|
|
var world = load("res://world/owniverse/owniverse.gd").new()
|
|
world.catalog.load_definitions(root.get_node("Global").OwniverseEntities)
|
|
world.state = initial.duplicate(true)
|
|
world.speed = speed
|
|
var elapsed: Array = []
|
|
for cycle in 6:
|
|
var start: int = Time.get_ticks_usec()
|
|
world.evolute(delta)
|
|
elapsed.append((Time.get_ticks_usec() - start) / 1000.0)
|
|
print("Speed %d, six consecutive %s-second steps, ms: %s" % [speed, delta, elapsed])
|
|
for entity in world.catalog.entities.values(): entity.free()
|
|
world.free()
|
|
quit()
|