From 5c8c28358e8ae4e4ae8b73469e7b5ceedeee0539 Mon Sep 17 00:00:00 2001 From: LinuxUserGD Date: Tue, 3 Jan 2023 21:38:13 +0000 Subject: [PATCH] add benchmark from https://github.com/godotengine/godot/pull/70838 --- test/benchmark.gd | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test/benchmark.gd b/test/benchmark.gd index b5d4b35..e551a0e 100644 --- a/test/benchmark.gd +++ b/test/benchmark.gd @@ -16,9 +16,44 @@ func _init() -> void: info("string") start_ms = Time.get_ticks_msec() check(start_ms, string(), 300000) + info("pr") + start_ms = Time.get_ticks_msec() + check(start_ms, pr(), 6553600) + self.quit() + info("pr_typed") + start_ms = Time.get_ticks_msec() + check(start_ms, pr_typed(), 6553600) self.quit() return +func pr() -> int: + const elems = 6553600 + var arr = [] + for x in range(elems): + arr.append(randi() % elems) + var acc = 0.0 + for e in arr: + var e2 = arr[e] + var e3 = arr[e2] + acc += e * e2 + acc *= e3 + e + acc = sqrt(acc) + return arr.size() + +func pr_typed() -> int: + const elems: int = 6553600 + var arr: PackedInt32Array = [] + for x in range(elems): + arr.append(randi() % elems) + var acc : float = 0.0 + for e in arr: + var e2 :int = arr[e] + var e3 :int = arr[e2] + acc += e * e2 + acc *= e3 + e + acc = sqrt(acc) + return arr.size() + func arr() -> int: var array: Array = [] while array.size() < 1500: