mirror of
https://github.com/godotengine/godot-benchmarks.git
synced 2025-12-31 09:49:13 +03:00
Allow the benchmark time limit to be changed by individual benchmarks (#73)
This commit is contained in:
committed by
GitHub
parent
6630e6e6c1
commit
331cd6d36c
@@ -1,8 +1,9 @@
|
|||||||
class_name Benchmark
|
class_name Benchmark
|
||||||
|
|
||||||
|
|
||||||
|
## Set default benchmark time limit to 5 seconds (5 million microseconds).
|
||||||
|
var benchmark_time := 5e6
|
||||||
var test_render_cpu : = false
|
var test_render_cpu : = false
|
||||||
var test_render_gpu : = false
|
var test_render_gpu : = false
|
||||||
var test_idle : = false
|
var test_idle : = false
|
||||||
var test_physics : = false
|
var test_physics : = false
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ class TestScene:
|
|||||||
|
|
||||||
|
|
||||||
func _init() -> void:
|
func _init() -> void:
|
||||||
|
benchmark_time = 10e6
|
||||||
test_physics = true
|
test_physics = true
|
||||||
test_idle = true
|
test_idle = true
|
||||||
|
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ class TestScene:
|
|||||||
|
|
||||||
|
|
||||||
func _init() -> void:
|
func _init() -> void:
|
||||||
|
benchmark_time = 10e6
|
||||||
test_physics = true
|
test_physics = true
|
||||||
test_idle = true
|
test_idle = true
|
||||||
|
|
||||||
|
|||||||
@@ -11,109 +11,110 @@ var square_mesh := QuadMesh.new()
|
|||||||
var circle_mesh := SphereMesh.new()
|
var circle_mesh := SphereMesh.new()
|
||||||
|
|
||||||
func _init() -> void:
|
func _init() -> void:
|
||||||
square_mesh.size = Vector2(20.0, 20.0);
|
square_mesh.size = Vector2(20.0, 20.0);
|
||||||
circle_mesh.radius = 10.0;
|
circle_mesh.radius = 10.0;
|
||||||
circle_mesh.height = 20.0;
|
circle_mesh.height = 20.0;
|
||||||
test_physics = true
|
benchmark_time = 10e6
|
||||||
test_idle = true
|
test_physics = true
|
||||||
|
test_idle = true
|
||||||
|
|
||||||
|
|
||||||
func setup_scene(create_body_func: Callable, unique_shape: bool, ccd_mode: RigidBody2D.CCDMode, boundary: bool, num_shapes: int) -> Node2D:
|
func setup_scene(create_body_func: Callable, unique_shape: bool, ccd_mode: RigidBody2D.CCDMode, boundary: bool, num_shapes: int) -> Node2D:
|
||||||
var scene_root := Node2D.new()
|
var scene_root := Node2D.new()
|
||||||
|
|
||||||
if VISUALIZE:
|
if VISUALIZE:
|
||||||
var camera := Camera2D.new()
|
var camera := Camera2D.new()
|
||||||
camera.position = Vector2(0.0, -100.0)
|
camera.position = Vector2(0.0, -100.0)
|
||||||
camera.zoom = Vector2(0.5, 0.5)
|
camera.zoom = Vector2(0.5, 0.5)
|
||||||
scene_root.add_child(camera)
|
scene_root.add_child(camera)
|
||||||
|
|
||||||
if boundary:
|
if boundary:
|
||||||
var pit := StaticBody2D.new();
|
var pit := StaticBody2D.new();
|
||||||
pit.add_child(create_wall(Vector2(SPREAD_H, 0.0), -0.1))
|
pit.add_child(create_wall(Vector2(SPREAD_H, 0.0), -0.1))
|
||||||
pit.add_child(create_wall(Vector2(-SPREAD_H, 0.0), 0.1))
|
pit.add_child(create_wall(Vector2(-SPREAD_H, 0.0), 0.1))
|
||||||
scene_root.add_child(pit);
|
scene_root.add_child(pit);
|
||||||
|
|
||||||
for _i in num_shapes:
|
for _i in num_shapes:
|
||||||
var body: RigidBody2D = create_body_func.call(unique_shape, ccd_mode)
|
var body: RigidBody2D = create_body_func.call(unique_shape, ccd_mode)
|
||||||
body.position = Vector2(randf_range(-SPREAD_H, SPREAD_H), randf_range(0.0, -SPREAD_V))
|
body.position = Vector2(randf_range(-SPREAD_H, SPREAD_H), randf_range(0.0, -SPREAD_V))
|
||||||
scene_root.add_child(body)
|
scene_root.add_child(body)
|
||||||
|
|
||||||
return scene_root
|
return scene_root
|
||||||
|
|
||||||
|
|
||||||
func create_wall(position: Vector2, rotation: float) -> CollisionShape2D:
|
func create_wall(position: Vector2, rotation: float) -> CollisionShape2D:
|
||||||
var wall := CollisionShape2D.new()
|
var wall := CollisionShape2D.new()
|
||||||
wall.shape = boundary_shape
|
wall.shape = boundary_shape
|
||||||
wall.position = position
|
wall.position = position
|
||||||
wall.rotation = rotation
|
wall.rotation = rotation
|
||||||
return wall
|
return wall
|
||||||
|
|
||||||
|
|
||||||
func create_random_shape(unique_shape: bool, ccd_mode: RigidBody2D.CCDMode) -> RigidBody2D:
|
func create_random_shape(unique_shape: bool, ccd_mode: RigidBody2D.CCDMode) -> RigidBody2D:
|
||||||
match randi_range(0, 1):
|
match randi_range(0, 1):
|
||||||
0: return create_square(unique_shape, ccd_mode)
|
0: return create_square(unique_shape, ccd_mode)
|
||||||
_: return create_circle(unique_shape, ccd_mode)
|
_: return create_circle(unique_shape, ccd_mode)
|
||||||
|
|
||||||
|
|
||||||
func create_square(unique_shape: bool, ccd_mode: RigidBody2D.CCDMode) -> RigidBody2D:
|
func create_square(unique_shape: bool, ccd_mode: RigidBody2D.CCDMode) -> RigidBody2D:
|
||||||
var rigid_body := RigidBody2D.new()
|
var rigid_body := RigidBody2D.new()
|
||||||
var collision_shape := CollisionShape2D.new()
|
var collision_shape := CollisionShape2D.new()
|
||||||
rigid_body.continuous_cd = ccd_mode
|
rigid_body.continuous_cd = ccd_mode
|
||||||
|
|
||||||
if VISUALIZE:
|
if VISUALIZE:
|
||||||
var mesh_instance := MeshInstance2D.new()
|
var mesh_instance := MeshInstance2D.new()
|
||||||
mesh_instance.mesh = square_mesh
|
mesh_instance.mesh = square_mesh
|
||||||
rigid_body.add_child(mesh_instance)
|
rigid_body.add_child(mesh_instance)
|
||||||
|
|
||||||
if unique_shape:
|
if unique_shape:
|
||||||
collision_shape.shape = RectangleShape2D.new()
|
collision_shape.shape = RectangleShape2D.new()
|
||||||
else:
|
else:
|
||||||
# Reuse existing shape.
|
# Reuse existing shape.
|
||||||
collision_shape.shape = square_shape
|
collision_shape.shape = square_shape
|
||||||
rigid_body.add_child(collision_shape)
|
rigid_body.add_child(collision_shape)
|
||||||
|
|
||||||
return rigid_body
|
return rigid_body
|
||||||
|
|
||||||
|
|
||||||
func create_circle(unique_shape: bool, ccd_mode: RigidBody2D.CCDMode) -> RigidBody2D:
|
func create_circle(unique_shape: bool, ccd_mode: RigidBody2D.CCDMode) -> RigidBody2D:
|
||||||
var rigid_body := RigidBody2D.new()
|
var rigid_body := RigidBody2D.new()
|
||||||
var collision_shape := CollisionShape2D.new()
|
var collision_shape := CollisionShape2D.new()
|
||||||
rigid_body.continuous_cd = ccd_mode
|
rigid_body.continuous_cd = ccd_mode
|
||||||
|
|
||||||
if VISUALIZE:
|
if VISUALIZE:
|
||||||
var mesh_instance := MeshInstance2D.new()
|
var mesh_instance := MeshInstance2D.new()
|
||||||
mesh_instance.mesh = circle_mesh
|
mesh_instance.mesh = circle_mesh
|
||||||
rigid_body.add_child(mesh_instance)
|
rigid_body.add_child(mesh_instance)
|
||||||
|
|
||||||
if unique_shape:
|
if unique_shape:
|
||||||
collision_shape.shape = CircleShape2D.new()
|
collision_shape.shape = CircleShape2D.new()
|
||||||
else:
|
else:
|
||||||
# Reuse existing shape.
|
# Reuse existing shape.
|
||||||
collision_shape.shape = circle_shape
|
collision_shape.shape = circle_shape
|
||||||
rigid_body.add_child(collision_shape)
|
rigid_body.add_child(collision_shape)
|
||||||
|
|
||||||
return rigid_body
|
return rigid_body
|
||||||
|
|
||||||
|
|
||||||
func benchmark_2000_rigid_body_2d_squares() -> Node2D:
|
func benchmark_2000_rigid_body_2d_squares() -> Node2D:
|
||||||
return setup_scene(create_square, false, RigidBody2D.CCD_MODE_DISABLED, true, 2000)
|
return setup_scene(create_square, false, RigidBody2D.CCD_MODE_DISABLED, true, 2000)
|
||||||
|
|
||||||
|
|
||||||
func benchmark_2000_rigid_body_2d_circles() -> Node2D:
|
func benchmark_2000_rigid_body_2d_circles() -> Node2D:
|
||||||
return setup_scene(create_circle, false, RigidBody2D.CCD_MODE_DISABLED, true, 2000)
|
return setup_scene(create_circle, false, RigidBody2D.CCD_MODE_DISABLED, true, 2000)
|
||||||
|
|
||||||
|
|
||||||
func benchmark_2000_rigid_body_2d_mixed() -> Node2D:
|
func benchmark_2000_rigid_body_2d_mixed() -> Node2D:
|
||||||
return setup_scene(create_random_shape, false, RigidBody2D.CCD_MODE_DISABLED, true, 2000)
|
return setup_scene(create_random_shape, false, RigidBody2D.CCD_MODE_DISABLED, true, 2000)
|
||||||
|
|
||||||
|
|
||||||
func benchmark_2000_rigid_body_2d_unique() -> Node2D:
|
func benchmark_2000_rigid_body_2d_unique() -> Node2D:
|
||||||
return setup_scene(create_random_shape, true, RigidBody2D.CCD_MODE_DISABLED, true, 2000)
|
return setup_scene(create_random_shape, true, RigidBody2D.CCD_MODE_DISABLED, true, 2000)
|
||||||
|
|
||||||
|
|
||||||
func benchmark_2000_rigid_body_2d_continuous() -> Node2D:
|
func benchmark_2000_rigid_body_2d_continuous() -> Node2D:
|
||||||
return setup_scene(create_random_shape, false, RigidBody2D.CCD_MODE_CAST_SHAPE, true, 2000)
|
return setup_scene(create_random_shape, false, RigidBody2D.CCD_MODE_CAST_SHAPE, true, 2000)
|
||||||
|
|
||||||
|
|
||||||
func benchmark_2000_rigid_body_2d_unbound() -> Node2D:
|
func benchmark_2000_rigid_body_2d_unbound() -> Node2D:
|
||||||
return setup_scene(create_random_shape, false, RigidBody2D.CCD_MODE_DISABLED, false, 2000)
|
return setup_scene(create_random_shape, false, RigidBody2D.CCD_MODE_DISABLED, false, 2000)
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ var box_mesh := BoxMesh.new()
|
|||||||
var sphere_mesh := SphereMesh.new()
|
var sphere_mesh := SphereMesh.new()
|
||||||
|
|
||||||
func _init() -> void:
|
func _init() -> void:
|
||||||
|
benchmark_time = 10e6
|
||||||
test_physics = true
|
test_physics = true
|
||||||
test_idle = true
|
test_idle = true
|
||||||
|
|
||||||
|
|||||||
@@ -165,10 +165,10 @@ func run_test(test_id: TestID) -> void:
|
|||||||
for i in 3:
|
for i in 3:
|
||||||
await get_tree().process_frame
|
await get_tree().process_frame
|
||||||
|
|
||||||
|
var time_limit: int = bench_script.get("benchmark_time")
|
||||||
begin_time = Time.get_ticks_usec()
|
begin_time = Time.get_ticks_usec()
|
||||||
|
|
||||||
# Time limit of 5 seconds (5 million microseconds).
|
while (Time.get_ticks_usec() - begin_time) < time_limit:
|
||||||
while (Time.get_ticks_usec() - begin_time) < 5e6:
|
|
||||||
await get_tree().process_frame
|
await get_tree().process_frame
|
||||||
|
|
||||||
results.render_cpu += RenderingServer.viewport_get_measured_render_time_cpu(get_tree().root.get_viewport_rid()) + RenderingServer.get_frame_setup_time_cpu()
|
results.render_cpu += RenderingServer.viewport_get_measured_render_time_cpu(get_tree().root.get_viewport_rid()) + RenderingServer.get_frame_setup_time_cpu()
|
||||||
|
|||||||
Reference in New Issue
Block a user