Skip to content
This repository has been archived by the owner on Dec 7, 2020. It is now read-only.

Commit

Permalink
Add bunnymark project and first run results
Browse files Browse the repository at this point in the history
  • Loading branch information
cart committed Oct 23, 2017
1 parent 7dec911 commit 64a79cf
Show file tree
Hide file tree
Showing 21 changed files with 923 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.import/
.mono/
.vscode/
lib/
logs/
bin/
cpp_bindings/
godot_headers/
*.os
39 changes: 39 additions & 0 deletions BenchmarkCPP.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[gd_scene load_steps=4 format=2]

[ext_resource path="res://GUI.tscn" type="PackedScene" id=1]

[sub_resource type="GDNativeLibrary" id=1]

platform/X11_32bit = ""
platform/X11_64bit = "res://lib/BenchmarkCPP.so"
platform/Windows_32bit = ""
platform/Windows_64bit = ""
platform/OSX = ""
platform/Android = ""
platform/iOS_32bit = ""
platform/iOS_64bit = ""
platform/WebAssembly = ""
_sections_unfolded = [ "platform" ]

[sub_resource type="NativeScript" id=2]

resource_name = "BenchmarkCPP"
class_name = "BenchmarkCPP"
library = SubResource( 1 )

[node name="Scene" type="Node2D"]

position = Vector2( 35.1976, 30.6851 )

[node name="Sprites" type="Node2D" parent="."]

script = SubResource( 2 )

[node name="gui" parent="." instance=ExtResource( 1 )]

margin_left = -36.0
margin_top = -31.0
margin_right = 114.0
margin_bottom = 169.0


106 changes: 106 additions & 0 deletions BenchmarkCS.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
using Godot;
using System;
using System.Collections.Generic;

public class BenchmarkCS : Node2D
{
private class Pair
{
public Sprite Sprite;
public Vector2 Vector;
}

[Export]
Texture TBunny;
List<Pair> bunnies = new List<Pair>();
int grav = 500;
float elapsed = 0.0f;
Vector2 screenSize;
Random random = new Random();

public override void _Ready()
{
screenSize = GetViewportRect().Size;
GetNode("../gui/list/add").Connect("pressed", this, "AddBunnies");

for (var i = 0; i < 10; i++)
{
AddBunny();
}
}

public override void _Process(float delta)
{
elapsed = elapsed + delta;
screenSize = GetViewportRect().Size;
if (elapsed > 1)
{
((Label)GetNode("../gui/list/fps")).Text = $"FPS: {Engine.GetFramesPerSecond()}";
elapsed = 0;
}

for (var i = 0; i < bunnies.Count; i++)
{
var bunny = bunnies[i];
var position = bunny.Sprite.Position;
var newPosition = bunny.Vector;

position.x += newPosition.x * delta;
position.y += newPosition.y * delta;

newPosition.y += grav * delta;

if (position.x > screenSize.x)
{
newPosition.x *= -1;
position.x = screenSize.x;
}

if (position.x < 0)
{
newPosition.x *= -1;
position.x = 0;
}

if (position.y > screenSize.y)
{
position.y = screenSize.y;
if (random.NextDouble() > 0.5)
{
newPosition.y = (random.Next() % 1100 + 50);
}
else
{
newPosition.y *= -0.85f;
}
}

if (position.y < 0)
{
newPosition.y = 0;
position.y = 0;
}

bunny.Sprite.Position = position;
bunny.Vector = newPosition;
}
}

public void AddBunny()
{
var bunny = new Sprite();
bunny.SetTexture(TBunny);
AddChild(bunny);
bunny.Position = new Vector2(screenSize.x / 2, screenSize.y / 2);
bunnies.Add(new Pair() { Sprite = bunny, Vector = new Vector2(random.Next() % 200 + 50, random.Next() % 200 + 50) });
((Label)GetNode("../gui/list/count")).Text = $"Bunny count: {bunnies.Count}";
}

public void AddBunnies()
{
for (var i = 0; i < 100; i++)
{
AddBunny();
}
}
}
23 changes: 23 additions & 0 deletions BenchmarkCS.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[gd_scene load_steps=4 format=2]

[ext_resource path="res://BenchmarkCS.cs" type="Script" id=1]
[ext_resource path="res://bunny.png" type="Texture" id=2]
[ext_resource path="res://GUI.tscn" type="PackedScene" id=3]

[node name="Scene" type="Node2D"]

position = Vector2( 35.1976, 30.6851 )

[node name="Sprites" type="Node2D" parent="."]

script = ExtResource( 1 )
TBunny = ExtResource( 2 )

[node name="gui" parent="." instance=ExtResource( 3 )]

margin_left = -36.0
margin_top = -31.0
margin_right = 114.0
margin_bottom = 169.0


67 changes: 67 additions & 0 deletions BenchmarkGD.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
extends Node2D

export(Texture) var t_bunny

var bunnies = []
var grav = 500
var screen_size
var elapsed = 0

func _ready():
screen_size = get_viewport_rect().size
get_node("../gui/list/add").connect("pressed", self, "add_bunnies")

for i in range(10): add_bunny()

func _process(delta):
elapsed = elapsed + delta
screen_size = get_viewport_rect().size
if elapsed > 1:
get_node('../gui/list/fps').set_text('FPS: ' + str(Engine.get_frames_per_second()))
elapsed = 0

for i in range(bunnies.size()):
var bunny = bunnies[i]
var pos = bunny[0].position
var newPosition = bunny[1]

pos.x += newPosition.x * delta
pos.y += newPosition.y * delta

newPosition.y += grav * delta

if pos.x > screen_size.x:
newPosition.x *= -1
pos.x = screen_size.x

if pos.x < 0:
newPosition.x *= -1
pos.x = 0

if pos.y > screen_size.y:
pos.y = screen_size.y
if randf() > 0.5:
newPosition.y = -(randi() % 1100 + 50)
else:
newPosition.y *= -0.85

if pos.y < 0:
newPosition.y = 0
pos.y = 0

bunny[0].position = pos
bunny[1] = newPosition

func add_bunny():
var bunny = Sprite.new()
bunny.set_texture(t_bunny)
add_child(bunny)

bunny.position = Vector2(screen_size.x / 2, screen_size.y / 2)
bunnies.append([bunny, Vector2(randi() % 200 + 50, randi() % 200 + 50)])

get_node('../gui/list/count').set_text('Bunny count: ' + str(bunnies.size()))

func add_bunnies():
for i in range(0,100):
add_bunny()
23 changes: 23 additions & 0 deletions BenchmarkGD.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[gd_scene load_steps=4 format=2]

[ext_resource path="res://BenchmarkGD.gd" type="Script" id=1]
[ext_resource path="res://bunny.png" type="Texture" id=2]
[ext_resource path="res://GUI.tscn" type="PackedScene" id=3]

[node name="Scene" type="Node2D"]

position = Vector2( 35.1976, 30.6851 )

[node name="Sprites" type="Node2D" parent="."]

script = ExtResource( 1 )
t_bunny = ExtResource( 2 )

[node name="gui" parent="." instance=ExtResource( 3 )]

margin_left = -36.0
margin_top = -31.0
margin_right = 114.0
margin_bottom = 169.0


52 changes: 52 additions & 0 deletions BenchmarkResults.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Godot 3.0 Bunnymark: GDScript vs C#/Mono vs GDNative(CPP)

Renders an increasing number of bunny sprites until a stable 60fps is hit. This is a decent test of real world usage as it combines Godot api usage with raw computation.

GDScript example adapted from: https://github.com/curly-brace/godot-bunnies. Thanks @curly-brace!

## Benchmark Run - October 22, 2017

*Standard*

| Language | Bunnies Rendered |
|--------------------|------------------|
| GDScript (Debug) | 9110 |
| GDScript (Release) | 11410 |
| C#/Mono | 20510 |
| GDNative (CPP) | 32010 |

*Standard + one get_children() call per _process*

| Language | Bunnies Rendered |
|--------------------|------------------|
| GDScript (Debug) | 8310 |
| GDScript (Release) | 11210 |
| C#/Mono | 15610 |
| GDNative (CPP) | 31510 |

*Standard + five get_children() calls per _process*

| Language | Bunnies Rendered |
|--------------------|------------------|
| GDScript (Release) | 10710 |
| C#/Mono | 10810 |
| GDNative (CPP) | 27410 |

C#/Mono rendered 1.80x more bunnies than GDScript. GDNative (CPP) rendered 1.56x more bunnies than C#/Mono and 2.81x more bunnies than GDScript.

As a comparison to another engine, I ran the [Pixi.js bunny-mark](https://pixijs.github.io/bunny-mark/) (which does the same thing) and rendered 35000 bunnies at 60fps.

### Hardware:

* CPU: Intel i7 7700k 4.2GHz
* GPU: Nvidia GeForce GTX 1070
* RAM: 16GB DDR4

### Remarks

These results played out as one would expect:
* GDScript < C#/Mono < GDNative (CPP).
* In the second test I added a get\_children() call to test marshalling/unmarshalling performance. get\_children() had almost no effect on GDNative's performance (-1.56%) and GDScripts performance (-1.75%) as the array was not copied. But it did have a significant effect on C#'s performance (-15.3%)
* The third test illustrates what a landmine the C# marshalling is. It only took 5 get\_children() calls to bring C#'s performance down to GDScript's performance. Use enough calls like this and you could easily get performance that is worse than any of the other options. Be wary of calling Godot apis from C# that set/return Arrays or Dictionaries.
* In C# the game jumped / framerates dipped significantly (ex: from ~100 fps to ~80fps) after each click of the "add bunnies" button. That did not happen for any of the other languages.
* Across all languages there was a perceivable "skip" about every 10 seconds. This was independent of bunny count
56 changes: 56 additions & 0 deletions Bunnymark.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{5CB3E26B-58B4-411D-B7B9-6AAD68C8950F}</ProjectGuid>
<OutputType>Library</OutputType>
<OutputPath>.mono/temp/bin/$(Configuration)</OutputPath>
<RootNamespace>Bunnymark</RootNamespace>
<AssemblyName>Bunnymark</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<BaseIntermediateOutputPath>.mono/temp/obj</BaseIntermediateOutputPath>
<IntermediateOutputPath>$(BaseIntermediateOutputPath)/$(Configuration)</IntermediateOutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Tools|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<DefineConstants>DEBUG;TOOLS;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<ItemGroup>
<Reference Include="GodotSharp">
<HintPath>$(ProjectDir)/.mono/assemblies/GodotSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="GodotSharpEditor" Condition=" '$(Configuration)' == 'Tools' ">
<HintPath>$(ProjectDir)/.mono/assemblies/GodotSharpEditor.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="BenchmarkCS.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
Loading

0 comments on commit 64a79cf

Please sign in to comment.