89 lines
1.4 KiB
GDScript3
Raw Normal View History

2024-02-23 20:32:13 +00:00
extends Node3D
2024-02-15 13:57:08 +00:00
var n := 1000000
2024-02-23 20:32:13 +00:00
var pass_time := 0.0
2024-02-15 13:57:08 +00:00
var benchmarks = [
"pass",
"get_node",
"find_child",
"get_child",
"get_parent",
"get_viewport",
"get_tree",
2024-02-23 20:32:13 +00:00
"get_ticks_msec",
"get_ticks_usec",
"get_unix_time_from_system",
"get_world_3d",
"script_func_call",
2024-02-15 13:57:08 +00:00
"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):
2024-02-23 20:32:13 +00:00
var t := Time.get_unix_time_from_system()
2024-02-15 13:57:08 +00:00
callable.call()
2024-02-23 20:32:13 +00:00
prints(round((Time.get_unix_time_from_system() - t) / n * 1000000000), "ns")
2024-02-15 13:57:08 +00:00
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()
2024-02-23 20:32:13 +00:00
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()
2024-02-15 13:57:08 +00:00
func _create_timer():
var tree := get_tree()
for i in range(n):
2024-02-23 20:32:13 +00:00
tree.create_timer(0)
func empty():
pass