Added more benchmarks

This commit is contained in:
Eduard Urbach 2024-02-23 21:32:13 +01:00
parent fcee55d9a4
commit 19c1d3e74c
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
2 changed files with 34 additions and 8 deletions

View File

@ -1,6 +1,7 @@
extends Node
extends Node3D
var n := 1000000
var pass_time := 0.0
var benchmarks = [
"pass",
"get_node",
@ -9,6 +10,11 @@ var benchmarks = [
"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",
]
@ -21,12 +27,9 @@ func _ready():
get_tree().quit()
func bench(callable: Callable):
var t := now()
var t := Time.get_unix_time_from_system()
callable.call()
prints(round((now() - t) / n * 1000000000), "ns")
func now() -> float:
return Time.get_unix_time_from_system()
prints(round((Time.get_unix_time_from_system() - t) / n * 1000000000), "ns")
func _pass():
for i in range(n):
@ -56,8 +59,31 @@ 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

View File

@ -4,7 +4,7 @@
[node name="Benchmark" type="Node"]
[node name="Node" type="Node" parent="."]
[node name="Node" type="Node3D" parent="."]
script = ExtResource("1_363x2")
[node name="Child" type="Node" parent="Node"]