Skip to content

Commit

Permalink
perf(bench): Multiline bench improved, DashedLine bench
Browse files Browse the repository at this point in the history
  • Loading branch information
jirikostiha committed Oct 29, 2023
1 parent a30d278 commit 434f435
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 67 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using BenchmarkDotNet.Attributes;
using Godot;

namespace GodotSharpSome.Drawing2D.Benchmarks;

[MemoryDiagnoser]
public class DashedLineBenchmark
{
private readonly List<Vector2> _points = new(100);
private readonly DashedLine _dashedLine = new();

[Benchmark]
public DashedLine CreateDefault()
{
return new DashedLine();
}

[Benchmark]
public DashedLine CreateCustom()
{
return new DashedLine(5.5f, 4f);
}

[Benchmark]
public void CreateDefaultWithListAndPalette()
{
_points.Clear();
_dashedLine.AppendLine(_points, Vector2.Zero, new (0, 100));
}

[Benchmark]
public void CreateDefaultFourLineTypes()
{
_points.Clear();
DashedLine.AppendLine(_points, Vector2.Zero, new(0, 100), 12, 8);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,90 +10,36 @@ namespace GodotSharpSome.Drawing2D.Benchmarks;
public class MultilineBenchmarks
{
private readonly List<Vector2> _lines = new(17);

[Params(1000, 10_000, 100_000)]
public int N { get; set; }

[Benchmark]
public Multiline? CreateDefault()
{
Multiline? ml = null;
for (int i = 0; i < N; i++)
{
ml = new Multiline();
}
return ml;
}

[Benchmark]
public Multiline? CreateDefaultWithList()
{
Multiline? ml = null;
for (int i = 0; i < N; i++)
{
ml = new Multiline(_lines);
}
return ml;
}
private readonly List<(string Key, IStraightLineAppender Pen)> _customPalette = new(7) {
new ("solid", new SolidLine()), new ("dashed", new DashedLine())};

[Benchmark]
public Multiline? CreateDefaultFourLineTypes()
public Multiline CreateDefault()
{
Multiline? ml = null;
for (int i = 0; i < N; i++)
{
ml = Multiline.FourLineTypes();
}
return ml;
return new Multiline();
}

[Benchmark]
public Multiline? CreateCustomFourLineTypes()
public Multiline CreateDefaultWithList()
{
Multiline? ml = null;
for (int i = 0; i < N; i++)
{
ml = Multiline.FourLineTypes(6, 8);
}
return ml;
return new Multiline(_lines);
}

[Benchmark]
public Vector2[] AppendSolidLines()
public Multiline CreateDefaultWithListAndPalette()
{
var ml = new Multiline();
for (int i = 0; i < N; i++)
{
ml.AppendLine(Vector2.Zero, Vector2.One);
ml.AppendTriangle(Vector2.Zero, Vector2.One, Vector2.Up);
}

return ml.Points();
return new Multiline(_lines, _customPalette);
}

[Benchmark]
public Vector2[] AppendDashedLines()
public Multiline CreateDefaultFourLineTypes()
{
var ml = new Multiline(new DashedLine());
for (int i = 0; i < N; i++)
{
ml.AppendLine(Vector2.Zero, Vector2.One);
ml.AppendTriangle(Vector2.Zero, Vector2.One, Vector2.Up);
}

return ml.Points();
return Multiline.FourLineTypes();
}

[Benchmark]
public Vector2[] AppendDashedLinesDefaultAppender()
public Multiline CreateCustomFourLineTypes()
{
var ml = new Multiline(DashedLine.Default);
for (int i = 0; i < N; i++)
{
ml.AppendLine(Vector2.Zero, Vector2.One);
ml.AppendTriangle(Vector2.Zero, Vector2.One, Vector2.Up);
}

return ml.Points();
return Multiline.FourLineTypes(6, 8);
}
}
4 changes: 3 additions & 1 deletion src/quality/GodotSharpSome.Drawing2D.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public static void Main(string[] args)
.WithOption(ConfigOptions.JoinSummary, true)
.WithOption(ConfigOptions.DisableLogFile, true);

BenchmarkRunner.Run(typeof(Program).Assembly, config);
//BenchmarkRunner.Run(typeof(Program).Assembly, config);

BenchmarkRunner.Run<MultilineBenchmarks>(config);
}
}

0 comments on commit 434f435

Please sign in to comment.