63 lines
969 B
GDScript3
Raw Normal View History

2024-02-15 13:57:08 +00:00
extends Node
var n := 1000000
var benchmarks = [
"pass",
"get_node",
"find_child",
"get_child",
"get_parent",
"get_viewport",
"get_tree",
"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 := now()
callable.call()
prints(round((now() - t) / n * 1000000000), "ns")
func now() -> float:
return Time.get_unix_time_from_system()
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 _create_timer():
var tree := get_tree()
for i in range(n):
tree.create_timer(0)