Skip to content

Commit

Permalink
Merge pull request #32 from Calinou/add-various-benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
Calinou authored Aug 16, 2023
2 parents ab0756e + 64b7a69 commit f8b40e1
Show file tree
Hide file tree
Showing 17 changed files with 863 additions and 47 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,15 @@ This argument also supports globbing and can be used at the same time as `--incl

For each benchmark, the project will track how long the main thread spent setting up the scene,
then run the scene for five seconds and log the average per-frame statistics.
(All times given are in milliseconds.)

- **Render CPU:** Average CPU time spent per frame
- **Render GPU:** Average GPU time spent per frame
- **Idle:** Currently unimplemented
- **Physics:** Currently unimplemented
- **Main Thread Time:** Time spent setting up the scene on the main thread
(All times given are in milliseconds. Lower values are better.)

- **Render CPU:** Average CPU time spent rendering each frame (such as setting up draw calls).
This metric does *not* take process/physics process functions into account.
- **Render GPU:** Average GPU time spent per frame.
- **Idle:** Average CPU time spent in C++ and GDScript process functions per second.
- **Physics:** Average CPU time spent in C++ and GDScript physics process functions per second.
- **Main Thread Time:** Time spent setting up the scene on the main thread.
For rendering benchmarks, this acts as a loading time measurement.

Note that not all benchmarks involve running a scene (for example, GDScript benchmarks).
In those cases, per-frame statistics will not be recorded,
Expand Down
27 changes: 27 additions & 0 deletions benchmarks/core/callable.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
extends Benchmark

signal emitter

const ITERATIONS = 2_000_000

func function_callable() -> void:
pass


func benchmark_function_callable() -> void:
for i in ITERATIONS:
function_callable.call()


func benchmark_lambda_inline_callable() -> void:
for i in ITERATIONS:
(func lambda_callable() -> void: pass).call()


func benchmark_lambda_variable_callable() -> void:
var variable_callable := \
func lambda_callable() -> void:
pass

for i in ITERATIONS:
variable_callable.call()
33 changes: 33 additions & 0 deletions benchmarks/core/crypto.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
extends Benchmark

const ITERATIONS = 100_000

var crypto := Crypto.new()


func benchmark_generate_10_random_bytes() -> void:
for i in ITERATIONS:
crypto.generate_random_bytes(10)


func benchmark_generate_1k_random_bytes() -> void:
for i in ITERATIONS:
crypto.generate_random_bytes(1000)


func benchmark_generate_1m_random_bytes() -> void:
for i in ITERATIONS:
crypto.generate_random_bytes(1_000_000)


func benchmark_generate_1g_random_bytes() -> void:
for i in ITERATIONS:
crypto.generate_random_bytes(1_000_000_000)


func benchmark_generate_rsa_2048() -> void:
crypto.generate_rsa(2048)


func benchmark_generate_rsa_4096() -> void:
crypto.generate_rsa(4096)
92 changes: 92 additions & 0 deletions benchmarks/core/random_number_generator.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
extends Benchmark

const ITERATIONS = 10_000_000
const RANDOM_SEED = preload("res://main.gd").RANDOM_SEED

var rng := RandomNumberGenerator.new()

func benchmark_global_scope_randi() -> void:
# Reset the random seed to improve reproducibility of this benchmark.
seed(RANDOM_SEED)
for i in ITERATIONS:
randi()

# Reset the random seed again to improve reproducibility of other benchmarks.
seed(RANDOM_SEED)


func benchmark_randi() -> void:
rng.seed = RANDOM_SEED
for i in ITERATIONS:
rng.randi()
rng.seed = RANDOM_SEED


func benchmark_global_scope_randf() -> void:
seed(RANDOM_SEED)
for i in ITERATIONS:
randf()
seed(RANDOM_SEED)


func benchmark_randf() -> void:
rng.seed = RANDOM_SEED
for i in ITERATIONS:
rng.randf()
rng.seed = RANDOM_SEED


func benchmark_global_scope_randi_range() -> void:
seed(RANDOM_SEED)
for i in ITERATIONS:
randi_range(1234, 5678)
seed(RANDOM_SEED)


func benchmark_randi_range() -> void:
rng.seed = RANDOM_SEED
for i in ITERATIONS:
rng.randi_range(1234, 5678)
rng.seed = RANDOM_SEED


func benchmark_global_scope_randf_range() -> void:
seed(RANDOM_SEED)
for i in ITERATIONS:
randf_range(1234.0, 5678.0)
seed(RANDOM_SEED)


func benchmark_randf_range() -> void:
rng.seed = RANDOM_SEED
for i in ITERATIONS:
rng.randf_range(1234.0, 5678.0)
rng.seed = RANDOM_SEED


func benchmark_global_scope_randfn() -> void:
seed(RANDOM_SEED)
for i in ITERATIONS:
randfn(10.0, 2.0)
seed(RANDOM_SEED)


func benchmark_randfn() -> void:
rng.seed = RANDOM_SEED
for i in ITERATIONS:
rng.randfn(10.0, 2.0)
rng.seed = RANDOM_SEED


func benchmark_global_scope_randomize() -> void:
seed(RANDOM_SEED)
for i in ITERATIONS:
randomize()
seed(RANDOM_SEED)


func benchmark_randomize() -> void:
rng.seed = RANDOM_SEED
for i in ITERATIONS:
rng.randomize()
rng.seed = RANDOM_SEED
33 changes: 30 additions & 3 deletions benchmarks/core/signal.gd
Original file line number Diff line number Diff line change
@@ -1,12 +1,39 @@
extends Benchmark

signal emitter
signal emitter_params_1(arg1)
signal emitter_params_10(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10)

func on_emit():
const ITERATIONS = 1_000_000

func on_emit() -> void:
pass


func on_emit_params_1(_arg1) -> void:
pass


func on_emit_params_10(_arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8, _arg9, _arg10) -> void:
pass

func benchmark_emission():

func benchmark_emission_params_0() -> void:
emitter.connect(on_emit)
for i in 1000_000:
for i in ITERATIONS:
emitter.emit()
emitter.disconnect(on_emit)


func benchmark_emission_params_1() -> void:
emitter_params_1.connect(on_emit_params_1)
for i in ITERATIONS:
emitter_params_1.emit(i)
emitter_params_1.disconnect(on_emit_params_1)


func benchmark_emission_params_10() -> void:
emitter_params_10.connect(on_emit_params_10)
for i in ITERATIONS:
emitter_params_10.emit(i, i, i, i, i, i, i, i, i, i)
emitter_params_10.disconnect(on_emit_params_10)
8 changes: 4 additions & 4 deletions benchmarks/gdscript/alloc.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extends Benchmark
const ITERATIONS = 100_000


func benchmark_deep_tree():
func benchmark_deep_tree() -> void:
var rt := Node.new()
for i in ITERATIONS:
var n := Node.new()
Expand All @@ -18,13 +18,13 @@ func benchmark_deep_tree():
rt = n
rt.free()

func benchmark_wide_tree():
func benchmark_wide_tree() -> void:
var rt := Node.new()
for i in ITERATIONS:
rt.add_child(Node.new())
rt.free()

func benchmark_fragmentation():
func benchmark_fragmentation() -> void:
var top := Node.new()
for i in 5:
top.add_child(Node.new())
Expand All @@ -45,7 +45,7 @@ func benchmark_fragmentation():

top.free()

func benchmark_duplicate():
func benchmark_duplicate() -> void:
var rt := Node.new()
for i in 16:
var n := Node.new()
Expand Down
Loading

0 comments on commit f8b40e1

Please sign in to comment.