Benchmarks
Here’s some benchmarks (via boatbomber’s Benchmarker plugin) comparing the unoptimized version (v0.5.6) and the current optimized version (v0.5.7). I’ve edited Engine:Start()
locally to not connect a RenderStepped event before hand. So if you’re going to benchmark it, be sure to remove the RenderStepped connection and set dt as 1/60.
Also note, that in the benchmarks Engine:Start() has been made a non-yielding function. It is called multiple times by the plugin and not once every frame.
Each benchmark is ran for 2 seconds hence the number of function calls vary for different cases. Each benchmark has 100 data points.
Benchmark 1
Common Information:
- 50 RigidBodies.
- Not using Quadtrees.
- 50% RigidBodies are collidable while the other 50% are non-collidable.
- All RigidBodies are unanchored.
- All RigidBodies spawn at the same position.
- Zero events connected.
Code Used
return {
ParameterGenerator = function()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Unoptimized = require(ReplicatedStorage.Original.Nature2D)
local Optimized = require(ReplicatedStorage.Nature2D)
local World = Instance.new("ScreenGui")
local Canvas = Instance.new("Frame")
Canvas.Name = "Canvas"
Canvas.Size = UDim2.fromScale(1, 1)
Canvas.Parent = World
local function MakeRigidBodies(Engine, num: number)
local collidable = true
for i = 1, num do
local frame = Instance.new("Frame")
frame.AnchorPoint = Vector2.new(.5, .5)
frame.Size = UDim2.fromOffset(50, 50)
frame.Position = UDim2.fromScale(.5, .5)
frame.Parent = World.Canvas
Engine:Create("RigidBody", {
Mass = 1,
Object = frame,
Collidable = collidable,
Anchored = false
})
collidable = not collidable
end
end
local Engine1 = Unoptimized.init(World)
Engine1:UseQuadtrees(false)
MakeRigidBodies(Engine1, 50)
local Engine2 = Optimized.init(World)
Engine2:UseQuadtrees(false)
MakeRigidBodies(Engine2, 50)
return Engine1, Engine2
end;
Functions = {
["Unoptimized"] = function(Profiler, Engine1, Engine2)
Engine1:Start()
end;
["Optimized"] = function(Profiler, Engine1, Engine2)
Engine2:Start()
end;
};
}
Results
Unoptimized - 106.9603ms
Optimized - 33.5569ms
Benchmark 2
Common Information:
- 50 RigidBodies.
- Uses Quadtrees.
- 50% RigidBodies are collidable while the other 50% are non-collidable.
- All RigidBodies are unanchored.
- All RigidBodies spawn at the same position.
- Zero events connected.
Code Used
return {
ParameterGenerator = function()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Unoptimized = require(ReplicatedStorage.Original.Nature2D)
local Optimized = require(ReplicatedStorage.Nature2D)
local World = Instance.new("ScreenGui")
local Canvas = Instance.new("Frame")
Canvas.Name = "Canvas"
Canvas.Size = UDim2.fromScale(1, 1)
Canvas.Parent = World
local function MakeRigidBodies(Engine, num: number)
local collidable = true
for i = 1, num do
local frame = Instance.new("Frame")
frame.AnchorPoint = Vector2.new(.5, .5)
frame.Size = UDim2.fromOffset(50, 50)
frame.Position = UDim2.fromScale(.5, .5)
frame.Parent = World.Canvas
Engine:Create("RigidBody", {
Mass = 1,
Object = frame,
Collidable = collidable,
Anchored = false
})
collidable = not collidable
end
end
local Engine1 = Unoptimized.init(World)
Engine1:UseQuadtrees(true)
MakeRigidBodies(Engine1, 50)
local Engine2 = Optimized.init(World)
Engine2:UseQuadtrees(true)
MakeRigidBodies(Engine2, 50)
return Engine1, Engine2
end;
Functions = {
["Unoptimized"] = function(Profiler, Engine1, Engine2)
Engine1:Start()
end;
["Optimized"] = function(Profiler, Engine1, Engine2)
Engine2:Start()
end;
};
}
Results
Unoptimized - 70.2497ms
Optimized - 39.1559ms