extends Node3D var n := 1000000 var pass_time := 0.0 var benchmarks = [ "pass", "get_node", "find_child", "get_child", "get_parent", "get_viewport", "get_tree", "get_ticks_msec", "get_ticks_usec", "get_unix_time_from_system", "get_world_3d", "script_func_call", "create_timer", ] func _ready(): for b in benchmarks: print("%s:" % b) bench(self["_%s" % b]) await get_tree().create_timer(0.5).timeout get_tree().quit() func bench(callable: Callable): var t := Time.get_unix_time_from_system() callable.call() prints(round((Time.get_unix_time_from_system() - t) / n * 1000000000), "ns") func _pass(): for i in range(n): pass func _get_node(): for i in range(n): get_node("Child") func _find_child(): for i in range(n): find_child("Child") func _get_child(): for i in range(n): get_child(0) func _get_parent(): for i in range(n): get_parent() func _get_viewport(): for i in range(n): get_viewport() func _get_tree(): for i in range(n): get_tree() func _get_ticks_msec(): for i in range(n): Time.get_ticks_msec() func _get_ticks_usec(): for i in range(n): Time.get_ticks_usec() func _get_unix_time_from_system(): for i in range(n): Time.get_unix_time_from_system() func _get_world_3d(): for i in range(n): get_world_3d() func _script_func_call(): for i in range(n): empty() func _create_timer(): var tree := get_tree() for i in range(n): tree.create_timer(0) func empty(): pass