Skip to content

Commit

Permalink
Add basic performance tests for linked list
Browse files Browse the repository at this point in the history
Made out of curiosity.

See godotengine/godot-proposals#1522.
  • Loading branch information
Xrayez committed Sep 17, 2020
1 parent cb20def commit 893eb64
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 0 deletions.
Binary file added tests/perf/list/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions tests/perf/list/icon.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://icon.png"
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
58 changes: 58 additions & 0 deletions tests/perf/list/list.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
extends Node

const ELEMENT_COUNT = 10000

class Profiler:
var name: String
var t1: float
var t2: float

func start(p_name := "Profiling result"):
t1 = OS.get_ticks_msec()
name = p_name

func stop():
t2 = OS.get_ticks_msec()
var elapsed = t2 - t1
print("%s: %s msec" % [name, elapsed])
return elapsed

var profiler = Profiler.new()

func _ready():
var methods = get_method_list()
var tests = []
for m in methods:
if m.name.begins_with("test_"):
tests.push_back(m.name)
tests.sort()
for test in tests:
profiler.start(test)
call(test)
profiler.stop()

#===============================================================================
# Performance tests!
#===============================================================================
func test_array_push_back():
var array = Array()
for i in ELEMENT_COUNT:
array.push_back("Godot")


func test_array_push_front():
var array = Array()
for i in ELEMENT_COUNT:
array.push_front("Godot")


func test_list_push_back():
var list = LinkedList.new()
for i in ELEMENT_COUNT:
list.push_back("Goost")


func test_list_push_front():
var list = LinkedList.new()
for i in ELEMENT_COUNT:
list.push_front("Goost")
6 changes: 6 additions & 0 deletions tests/perf/list/list.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=2]

[ext_resource path="res://list.gd" type="Script" id=1]

[node name="list" type="Node"]
script = ExtResource( 1 )
20 changes: 20 additions & 0 deletions tests/perf/list/project.godot
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
; Engine configuration file.
; It's best edited using the editor UI and not directly,
; since the parameters that go here are not all obvious.
;
; Format:
; [section] ; section goes between []
; param=value ; assign values to parameters

config_version=4

_global_script_classes=[ ]
_global_script_class_icons={

}

[application]

config/name="Goost Linked List Performance Tests"
run/main_scene="res://list.tscn"
config/icon="res://icon.png"

0 comments on commit 893eb64

Please sign in to comment.