Add Bunnymark-style benchmarks (#65)

Co-authored-by: Hugo Locurcio <hugo.locurcio@hugo.pro>
This commit is contained in:
Francisco Demartino
2024-05-07 15:03:10 -03:00
committed by GitHub
parent a6aaa622e9
commit 01b9aaa062
6 changed files with 220 additions and 0 deletions

View File

@@ -0,0 +1,119 @@
extends Benchmark
func _init() -> void:
test_render_cpu = true
test_render_gpu = true
class Bunnymark extends Node2D:
var cam := Camera2D.new()
var texture := preload("res://supplemental/bunny.png")
var mi2d := preload("res://supplemental/bunny_meshinstance2d.tscn")
var rng := RandomNumberGenerator.new()
var gravity := Vector2(0.0, 980.0)
var count := 1
var canvasitem_draw_api := false
var meshinstance2d := false
var nodes := []
var speeds := []
var positions := []
var hues := []
func _init(settings: Dictionary) -> void:
count = settings.get("count", 1)
canvasitem_draw_api = settings.get("canvasitem_draw_api", false)
meshinstance2d = settings.get("meshinstance2d", false)
func _ready() -> void:
create_nodes()
add_child(cam)
func create_nodes() -> void:
for i in count:
var node
if not meshinstance2d:
node = Sprite2D.new()
else:
node = mi2d.instantiate()
hues.append(Color.from_hsv(
rng.randf_range(0.0, 1.0),
0.8,
0.8))
var speed := Vector2(
rng.randf_range(-400.0, 400.0),
rng.randf_range(-400.0, 400.0))
speeds.append(speed)
positions.append(Vector2(0, 0))
if not canvasitem_draw_api:
if not meshinstance2d:
node.texture = texture
node.self_modulate = hues[i]
nodes.append(node)
add_child(node)
func _process(time: float) -> void:
for i in count:
var spd = speeds[i]
var pos = positions[i]
var x_delta = abs(pos.x - 0)
if x_delta > 400:
spd *= Vector2(-1, 1)
var floor_delta = pos.y - 400
if floor_delta > 0:
positions[i] += Vector2(0, -2*floor_delta)
spd *= Vector2(1, -1)
spd += gravity * time
speeds[i] = spd
positions[i] += time*spd
if not canvasitem_draw_api:
for i in count:
var pos = positions[i]
var node = nodes[i]
node.transform.origin = pos
else:
queue_redraw()
func _draw() -> void:
if not canvasitem_draw_api:
return
for i in count:
var pos = positions[i]
draw_texture(texture, pos, hues[i])
func benchmark_bunnymark_canvasitem_draw_api_5000() -> Node2D:
return Bunnymark.new({ count = 5000, canvasitem_draw_api = true })
func benchmark_bunnymark_canvasitem_draw_api_10000() -> Node2D:
return Bunnymark.new({ count = 10000, canvasitem_draw_api = true })
func benchmark_bunnymark_canvasitem_draw_api_20000() -> Node2D:
return Bunnymark.new({ count = 20000, canvasitem_draw_api = true })
func benchmark_bunnymark_meshinstance2d_5000() -> Node2D:
return Bunnymark.new({ count = 5000, meshinstance2d = true })
func benchmark_bunnymark_meshinstance2d_10000() -> Node2D:
return Bunnymark.new({ count = 10000, meshinstance2d = true })
func benchmark_bunnymark_meshinstance2d_20000() -> Node2D:
return Bunnymark.new({ count = 20000, meshinstance2d = true })
func benchmark_bunnymark_sprite2d_5000() -> Node2D:
return Bunnymark.new({ count = 5000 })
func benchmark_bunnymark_sprite2d_10000() -> Node2D:
return Bunnymark.new({ count = 10000 })
func benchmark_bunnymark_sprite2d_20000() -> Node2D:
return Bunnymark.new({ count = 20000 })

BIN
supplemental/bunny.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 575 B

View File

@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bix3405cfiuk4"
path="res://.godot/imported/bunny.png-375c1d26843545e41dc2bd6f3e5267e0.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://supplemental/bunny.png"
dest_files=["res://.godot/imported/bunny.png-375c1d26843545e41dc2bd6f3e5267e0.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View File

@@ -0,0 +1,21 @@
[gd_scene load_steps=3 format=3 uid="uid://c7ntecauarpef"]
[ext_resource type="Texture2D" uid="uid://bix3405cfiuk4" path="res://supplemental/bunny.png" id="1_52gt6"]
[sub_resource type="ArrayMesh" id="ArrayMesh_hgweu"]
_surfaces = [{
"2d": true,
"aabb": AABB(-16, -16, 0, 32, 32, 0),
"attribute_data": PackedByteArray(0, 0, 80, 63, 205, 204, 204, 60, 0, 0, 80, 63, 51, 51, 115, 61, 0, 0, 128, 63, 102, 102, 54, 62, 0, 0, 128, 63, 0, 0, 96, 63, 205, 204, 120, 63, 0, 0, 96, 63, 51, 51, 99, 63, 0, 0, 128, 63, 0, 0, 0, 62, 0, 0, 128, 63, 0, 0, 0, 0, 102, 102, 94, 63, 0, 0, 0, 0, 0, 0, 64, 62, 0, 0, 128, 62, 102, 102, 230, 60, 0, 0, 128, 62, 0, 0, 0, 0, 102, 102, 190, 62, 0, 0, 0, 0, 51, 51, 251, 62, 0, 0, 192, 61, 102, 102, 6, 63, 0, 0, 192, 61, 102, 102, 18, 63, 0, 0, 0, 0, 51, 51, 67, 63, 0, 0, 0, 0),
"format": 34393296913,
"index_count": 42,
"index_data": PackedByteArray(15, 0, 0, 0, 1, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 13, 0, 14, 0, 15, 0, 15, 0, 1, 0, 3, 0, 4, 0, 6, 0, 8, 0, 8, 0, 9, 0, 11, 0, 13, 0, 15, 0, 3, 0, 3, 0, 4, 0, 8, 0, 8, 0, 11, 0, 12, 0, 12, 0, 13, 0, 3, 0, 3, 0, 8, 0, 12, 0),
"primitive": 3,
"uv_scale": Vector4(0, 0, 0, 0),
"vertex_count": 16,
"vertex_data": PackedByteArray(0, 0, 32, 65, 51, 51, 115, 193, 0, 0, 32, 65, 154, 153, 97, 193, 0, 0, 128, 65, 205, 204, 36, 193, 0, 0, 128, 65, 0, 0, 64, 65, 154, 153, 113, 65, 0, 0, 64, 65, 102, 102, 70, 65, 0, 0, 128, 65, 0, 0, 64, 193, 0, 0, 128, 65, 0, 0, 128, 193, 204, 204, 60, 65, 0, 0, 128, 193, 0, 0, 32, 193, 0, 0, 0, 193, 154, 153, 113, 193, 0, 0, 0, 193, 0, 0, 128, 193, 52, 51, 131, 192, 0, 0, 128, 193, 160, 153, 153, 190, 0, 0, 80, 193, 192, 204, 76, 63, 0, 0, 80, 193, 48, 51, 19, 64, 0, 0, 128, 193, 102, 102, 6, 65, 0, 0, 128, 193)
}]
[node name="bunny" type="MeshInstance2D"]
mesh = SubResource("ArrayMesh_hgweu")
texture = ExtResource("1_52gt6")

View File

@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"

View File

@@ -0,0 +1,40 @@
name: Continuous integration
on:
push:
pull_request:
workflow_dispatch:
jobs:
deploy:
name: Build and deploy to GitHub Pages
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Generate class reference table and build website
env:
HUGO_VERSION: '0.117.0'
run: |
curl -LO "https://github.com/gohugoio/hugo/releases/download/v$HUGO_VERSION/hugo_${HUGO_VERSION}_Linux-64bit.tar.gz"
tar xf "hugo_${HUGO_VERSION}_Linux-64bit.tar.gz" hugo
sudo mv hugo /usr/local/bin/
git clone --depth=1 https://github.com/godotengine/godot-benchmarks.git
# Copy benchmark JSONs to the web source so they can be included in the built website.
cp 2*.md godot-benchmarks/web/content
ls -l godot-benchmarks/web/content
hugo --minify --source=godot-benchmarks/web --destination="$PWD/public"
- name: Deploy to GitHub Pages 🚀
uses: JamesIves/github-pages-deploy-action@releases/v3
# Only deploy from the `main` branch, and never deploy from pull requests.
if: ${{ (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.ref == 'refs/heads/main' }}
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# The branch the action should deploy to.
BRANCH: gh-pages
# The folder the action should deploy.
FOLDER: public
# Artifacts are large, don't keep the branch's history
SINGLE_COMMIT: true