Skip to content

Commit 5b806d3

Browse files
committed
try add benchmarks
1 parent 1481176 commit 5b806d3

8 files changed

Lines changed: 63 additions & 21 deletions

.github/workflows/dotnet.yaml

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,63 @@ on:
55
branches: [ master ]
66
pull_request:
77
branches: [ master ]
8+
workflow_dispatch:
89

910
jobs:
10-
build:
11-
11+
build-and-test:
1212
strategy:
1313
matrix:
1414
os: [ ubuntu-latest, windows-latest, macos-latest ]
15-
dotnet-version: [ '8.0.x', '9.0.x', '10.0.x' ]
15+
dotnet-version: [ '10.0.x' ]
1616
runs-on: ${{ matrix.os }}
1717
steps:
18-
- uses: actions/checkout@v3
18+
- uses: actions/checkout@v4
1919
- name: Setup .NET
20-
uses: actions/setup-dotnet@v3
20+
uses: actions/setup-dotnet@v4
2121
with:
2222
dotnet-version: ${{ matrix.dotnet-version }}
23-
- name: Build with dotnet
23+
24+
- name: Build
2425
run: dotnet build -c Release
25-
- name: Run tests with coverage
26+
27+
- name: Run Tests
2628
run: |
27-
cd ./src/Hexecs.Tests/
2829
dotnet test -c Release --no-build /p:CollectCoverage=true /p:CoverletOutput=TestResults/ /p:CoverletOutputFormat=opencover
30+
2931
- name: Publish coverage report
30-
if: matrix.os == 'ubuntu-latest' && matrix.dotnet-version == '10.0.x'
31-
uses: codecov/codecov-action@v3
32+
if: matrix.os == 'ubuntu-latest'
33+
uses: codecov/codecov-action@v4
3234
with:
3335
token: ${{ secrets.CODECOV_TOKEN }}
36+
37+
benchmark:
38+
runs-on: ubuntu-latest
39+
needs: build-and-test
40+
steps:
41+
- uses: actions/checkout@v4
42+
43+
- name: Setup .NET
44+
uses: actions/setup-dotnet@v4
45+
with:
46+
dotnet-version: '10.0.x'
47+
48+
- name: Run Benchmarks
49+
run: |
50+
if [ "${{ github.event_name }}" == "pull_request" ]; then
51+
dotnet run -c Release --project ./src/Hexecs.Benchmarks/ -- --filter '*' --exporters json --join --job LowRuntime
52+
else
53+
dotnet run -c Release --project ./src/Hexecs.Benchmarks/ -- --filter '*' --exporters json --join
54+
fi
55+
56+
- name: Store benchmark result
57+
uses: benchmark-action/github-action-benchmark@v1
58+
with:
59+
tool: 'benchmarkdotnet'
60+
# BenchmarkDotNet при --join создает файл с именем '*-report-full.json' или 'BenchmarkRun-report.json'
61+
output-file-path: 'BenchmarkDotNet.Artifacts/results/BenchmarkRun-report.json'
62+
github-token: ${{ secrets.GITHUB_TOKEN }}
63+
auto-push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
64+
comment-on-alert: true
65+
fail-on-alert: true
66+
# Порог чувствительности: 120% (запас на шум облака)
67+
alert-threshold: "120%"

src/Hexecs.Benchmarks/Actors/ActorFilter2EnumerationBenchmark.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ namespace Hexecs.Benchmarks.Actors;
2222
[HideColumns("Job", "Error", "StdDev", "Median", "RatioSD")]
2323
public class ActorFilter2EnumerationBenchmark
2424
{
25-
private const int Count = 100_000;
25+
[Params(10_000, 100_000)]
26+
public int Count;
2627

2728
private ActorFilter<Attack, Defence> _filter = null!;
2829
private World _world = null!;

src/Hexecs.Benchmarks/Actors/ActorFilter3EnumerationBenchmark.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ namespace Hexecs.Benchmarks.Actors;
2323
[HideColumns("Job", "Error", "StdDev", "Median", "RatioSD")]
2424
public class ActorFilter3EnumerationBenchmark
2525
{
26-
private const int Count = 100_000;
26+
[Params(10_000, 100_000)]
27+
public int Count;
2728

2829
private ActorFilter<Attack, Defence, Speed> _filter = null!;
2930
private World _world = null!;

src/Hexecs.Benchmarks/Actors/CheckComponentExistsBenchmark.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ namespace Hexecs.Benchmarks.Actors;
2626
[HideColumns("Job", "Error", "StdDev", "Median", "RatioSD", "Count")]
2727
public class CheckComponentExistsBenchmark
2828
{
29-
private const int Count = 100_000;
29+
[Params(10_000, 100_000)]
30+
public int Count;
3031

3132
private ActorContext _context = null!;
3233
private DefaultEcs.World _defaultWorld = null!;

src/Hexecs.Benchmarks/Actors/CreateAddComponentsDestroyBenchmark.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ namespace Hexecs.Benchmarks.Actors;
2828
[HideColumns("Job", "Error", "StdDev", "Median", "RatioSD")]
2929
public class CreateAddComponentsDestroyBenchmark
3030
{
31-
[Params(1_000, 100_000, 500_000)] public int Count;
31+
[Params(1_000, 100_000, 500_000)]
32+
public int Count;
3233

3334
private List<DefaultEcs.EntitySet> _defaultSets = null!;
3435
private List<DefaultEcs.Entity> _defaultEntities = null!;

src/Hexecs.Benchmarks/Actors/UpdateSystemWithParallelWorkerBenchmark.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ namespace Hexecs.Benchmarks.Actors;
2525
[HideColumns("Job", "Error", "StdDev", "Median", "RatioSD")]
2626
public class UpdateSystemWithParallelWorkerBenchmark
2727
{
28-
private const int Count = 2_000_000;
28+
[Params(100_000, 1_000_000)]
29+
public int Count;
2930

3031
private DefaultEcs.World _defaultWorld = null!;
3132
private DefaultEcsParallelSystem _defaultSystem = null!;

src/Hexecs.Benchmarks/Collections/SparsePageDictionaryBenchmark.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public class SparsePageDictionaryBenchmark
3535
private uint[] _lookupKeys = null!;
3636
private uint[] _missingKeys = null!;
3737

38-
[Params(1_000)] public int N;
38+
[Params(500)]
39+
public int N;
3940

4041
[GlobalSetup]
4142
public void Setup()

src/Hexecs.Benchmarks/Collections/ThreadLocalStackBenchmark.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ namespace Hexecs.Benchmarks.Collections;
2323
[HideColumns("Job", "Error", "StdDev", "Median", "RatioSD", "Count")]
2424
public class ThreadLocalStackBenchmark
2525
{
26-
private const int Count = 100_000;
26+
[Params(10_000)]
27+
public int Count = 10_000;
28+
2729
private const int ThreadCount = 4;
2830

2931
private ConcurrentStack<uint> _concurrentStack = null!;
@@ -34,10 +36,10 @@ public class ThreadLocalStackBenchmark
3436
[Benchmark(Baseline = true)]
3537
public int ThreadLocalStack_Parallel()
3638
{
39+
var opsPerThread = Count / ThreadCount;
3740
var result = 0;
3841
Parallel.For(0, ThreadCount, _ =>
3942
{
40-
const int opsPerThread = Count / ThreadCount;
4143
for (var i = 0; i < opsPerThread; i++)
4244
{
4345
if (_threadLocalStack.TryPop(out var id))
@@ -53,10 +55,10 @@ public int ThreadLocalStack_Parallel()
5355
[Benchmark]
5456
public int ConcurrentStack_Parallel()
5557
{
58+
var opsPerThread = Count / ThreadCount;
5659
var result = 0;
5760
Parallel.For(0, ThreadCount, _ =>
5861
{
59-
const int opsPerThread = Count / ThreadCount;
6062
for (var i = 0; i < opsPerThread; i++)
6163
{
6264
if (_concurrentStack.TryPop(out var id))
@@ -72,10 +74,10 @@ public int ConcurrentStack_Parallel()
7274
[Benchmark]
7375
public int LockedStack_Parallel()
7476
{
77+
var opsPerThread = Count / ThreadCount;
7578
var result = 0;
7679
Parallel.For(0, ThreadCount, _ =>
7780
{
78-
const int opsPerThread = Count / ThreadCount;
7981
for (var i = 0; i < opsPerThread; i++)
8082
{
8183
if (TryPopLocked(out var id))
@@ -103,7 +105,7 @@ public void Setup()
103105
_threadLocalStack.Push(i);
104106
}
105107
}
106-
108+
107109
[GlobalCleanup]
108110
public void Cleanup()
109111
{

0 commit comments

Comments
 (0)