This repository was archived by the owner on Sep 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofiler.gd
More file actions
103 lines (78 loc) · 2.39 KB
/
profiler.gd
File metadata and controls
103 lines (78 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
extends Node
@export var time_per_mesh:float = 15
@export var runs:int = 8
@export var start_time:float = 10
@export var end_time:float = 1
@export var meshes:Array[Mesh]
@export var amounts:Array[int]
@onready var multi_mesh:MultiMeshInstance2D = %MultiMeshInstance2D
var frames_elapsed:int
var time_elapsed:float
var data:Array[TestData]
class TestData:
var grass_amount:int
var vertex_count:int
var avarage_frame_time:Array[float]
func _ready():
for mesh in meshes:
for amount in amounts:
var d:TestData = TestData.new()
d.grass_amount = amount
d.vertex_count = int(
mesh.resource_path
.trim_prefix("res://grass_meshes/grass_blade_")
.trim_suffix(".obj")
)
data.append(d)
perform_tests()
func _process(delta):
time_elapsed += delta
frames_elapsed += 1
func perform_tests():
await get_tree().create_timer(start_time).timeout
for i in runs:
for mesh in meshes:
for amount in amounts:
multi_mesh.multimesh.mesh = mesh
multi_mesh.multimesh.instance_count = amount
multi_mesh.populate_random()
var vertex_count:int = int(
mesh.resource_path
.trim_prefix("res://grass_meshes/grass_blade_")
.trim_suffix(".obj")
)
reset_profiler()
await get_tree().create_timer(time_per_mesh).timeout
var test_data:TestData = data.filter(func(d:TestData): return \
d.grass_amount == amount and \
d.vertex_count == vertex_count
)[0]
test_data.grass_amount = amount
test_data.vertex_count = vertex_count
test_data.avarage_frame_time.append(1000 * time_elapsed / frames_elapsed)
await get_tree().create_timer(end_time).timeout
save_resoults()
get_tree().quit()
func reset_profiler():
time_elapsed = 0
frames_elapsed = 0
func save_resoults():
var file := FileAccess.open("res://resoults.csv", FileAccess.WRITE)
var headline := PackedStringArray()
headline.append(" ")
for a in amounts:
headline.append(str(a))
file.store_csv_line(headline)
var last_vertex_count:int = 3
var line := PackedStringArray()
for d in data:
if last_vertex_count != d.vertex_count:
line = PackedStringArray([str(last_vertex_count)]) + line
last_vertex_count = d.vertex_count
file.store_csv_line(line)
line.clear()
line.append(str(d.avarage_frame_time
.reduce(func(accum, number): return accum + number, 0)
/ runs
))
file.store_csv_line(PackedStringArray([str(last_vertex_count)]) + line)