diff --git a/.github/workflows/pr-build.yml b/.github/workflows/pr-build.yml new file mode 100644 index 0000000..7e8421c --- /dev/null +++ b/.github/workflows/pr-build.yml @@ -0,0 +1,46 @@ +name: PR Build +on: + pull_request: + branches: "**" + +jobs: + build: + strategy: + matrix: + dotnet: ['8.x'] + name: "Test on .NET ${{ matrix.dotnet }}" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: "Setup .NET ${{ matrix.dotnet }}" + uses: actions/setup-dotnet@v4 + with: + dotnet-version: ${{ matrix.dotnet }} + - name: Restore dependencies + run: dotnet restore + - name: "Build on ${{ matrix.dotnet }}" + run: dotnet build --no-restore ./DemLock.Tests/DemLock.Tests.csproj + - name: "Test on ${{ matrix.dotnet }}" + run: dotnet test --no-build --verbosity normal + + benchmark: + strategy: + matrix: + dotnet: ['8.x'] + name: "Benchmark on ${{ matrix.dotnet }}" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: "Setup .NET ${{ matrix.dotnet }}" + uses: actions/setup-dotnet@v4 + with: + dotnet-version: ${{ matrix.dotnet }} + - name: Restore dependencies + run: dotnet restore + - name: "Build on ${{ matrix.dotnet }}" + run: dotnet build --no-restore -c Release ./DemLock.Benchmarks/DemLock.Benchmarks.csproj + # We need sudo so BenchmarkDotNet can set itself as high priority on the CPU. + # We're still running without any Github credentials/can only do stuff within + # the branch, so we should be good security wise. + - name: "Benchmark on ${{ matrix.dotnet }}" + run: sudo dotnet run -c Release --project ./DemLock.Benchmarks/DemLock.Benchmarks.csproj diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml new file mode 100644 index 0000000..4222395 --- /dev/null +++ b/.github/workflows/push.yml @@ -0,0 +1,46 @@ +name: Push +on: + push: + branches: "main" + +jobs: + build: + strategy: + matrix: + dotnet: ['8.x'] + name: "Test on .NET ${{ matrix.dotnet }}" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: "Setup .NET ${{ matrix.dotnet }}" + uses: actions/setup-dotnet@v4 + with: + dotnet-version: ${{ matrix.dotnet }} + - name: Restore dependencies + run: dotnet restore + - name: "Build on ${{ matrix.dotnet }}" + run: dotnet build --no-restore ./DemLock.Tests/DemLock.Tests.csproj + - name: "Test on ${{ matrix.dotnet }}" + run: dotnet test --no-build --verbosity normal + + benchmark: + strategy: + matrix: + dotnet: ['8.x'] + name: "Benchmark on ${{ matrix.dotnet }}" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: "Setup .NET ${{ matrix.dotnet }}" + uses: actions/setup-dotnet@v4 + with: + dotnet-version: ${{ matrix.dotnet }} + - name: Restore dependencies + run: dotnet restore + - name: "Build on ${{ matrix.dotnet }}" + run: dotnet build --no-restore -c Release ./DemLock.Benchmarks/DemLock.Benchmarks.csproj + # We need sudo so BenchmarkDotNet can set itself as high priority on the CPU. + # We're still running without any Github credentials/can only do stuff within + # the branch, so we should be good security wise. + - name: "Benchmark on ${{ matrix.dotnet }}" + run: sudo dotnet run -c Release --project ./DemLock.Benchmarks/DemLock.Benchmarks.csproj diff --git a/.gitignore b/.gitignore index a3dc7eb..5e5260b 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ obj/ riderModule.iml /_ReSharper.Caches/ .idea -DemLock.sln.DotSettings.user \ No newline at end of file +DemLock.sln.DotSettings.user +BenchmarkDotNet.Artifacts/ diff --git a/DemLock.Benchmarks/BenchmarkTests.cs b/DemLock.Benchmarks/BenchmarkTests.cs new file mode 100644 index 0000000..1bda531 --- /dev/null +++ b/DemLock.Benchmarks/BenchmarkTests.cs @@ -0,0 +1,41 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Running; +using DemLock.Parser; + +namespace DemLock.Tests; + +public class BenchmarkTests +{ + private readonly DemoParserConfig config; + private readonly DemoParser parser; + private readonly string demosPath; + + public BenchmarkTests() + { + config = new DemoParserConfig + { + LogMessageReads = false, + LogReadFrames = false + }; + parser = new DemoParser(config); + demosPath = Path.Combine(Directory.GetCurrentDirectory(), @"TestData"); + } + + [Benchmark] + public void FullMatch() + { + // Arrange + parser.Events.OnEntityUpdated += static (sender, eventArgs) => {}; + + // Act + parser.ProcessDemo(Path.Combine(demosPath, "benchmark_20240825_361e4b053.dem")); + } +} + +public class Program +{ + public static void Main() + { + _ = BenchmarkRunner.Run(); + } +} diff --git a/DemLock.Benchmarks/DemLock.Benchmarks.csproj b/DemLock.Benchmarks/DemLock.Benchmarks.csproj new file mode 100644 index 0000000..e81d471 --- /dev/null +++ b/DemLock.Benchmarks/DemLock.Benchmarks.csproj @@ -0,0 +1,22 @@ + + + Exe + net8.0 + enable + enable + + + + + + + + + PreserveNewest + + + + + + + diff --git a/DemLock.Benchmarks/TestData/README.md b/DemLock.Benchmarks/TestData/README.md new file mode 100644 index 0000000..126b3ba --- /dev/null +++ b/DemLock.Benchmarks/TestData/README.md @@ -0,0 +1,7 @@ +# DemLock benchmarks + +This folder contains benchmark demos for the parser, sourced from +tournaments whose files are available publically. The files are named according to the format +`benchmark__.dem`, where `YYYYMMDD` is the day the match +was played and `commit` is the [SteamDatabase/Protobufs](https://github.com/SteamDatabase/Protobufs) commit +of the version of protobuf being used. diff --git a/DemLock.Benchmarks/TestData/benchmark_20240825_361e4b053.dem b/DemLock.Benchmarks/TestData/benchmark_20240825_361e4b053.dem new file mode 100644 index 0000000..c302e7c Binary files /dev/null and b/DemLock.Benchmarks/TestData/benchmark_20240825_361e4b053.dem differ diff --git a/DemLock.sln b/DemLock.sln index 522d37c..4a4a9f8 100644 --- a/DemLock.sln +++ b/DemLock.sln @@ -12,6 +12,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DemLock.Entities", "DemLock EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DemLock.ClassMappingGenerator", "DemLock.ClassMappingGenerator\DemLock.ClassMappingGenerator\DemLock.ClassMappingGenerator.csproj", "{2BCD54C5-6D09-4ADF-BEF7-FF67FFF0F1D8}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DemLock.Benchmarks", "DemLock.Benchmarks\DemLock.Benchmarks.csproj", "{FF3B0F1B-3BE0-40B8-B508-5198AF2209BC}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -42,5 +44,9 @@ Global {2BCD54C5-6D09-4ADF-BEF7-FF67FFF0F1D8}.Debug|Any CPU.Build.0 = Debug|Any CPU {2BCD54C5-6D09-4ADF-BEF7-FF67FFF0F1D8}.Release|Any CPU.ActiveCfg = Release|Any CPU {2BCD54C5-6D09-4ADF-BEF7-FF67FFF0F1D8}.Release|Any CPU.Build.0 = Release|Any CPU + {FF3B0F1B-3BE0-40B8-B508-5198AF2209BC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FF3B0F1B-3BE0-40B8-B508-5198AF2209BC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FF3B0F1B-3BE0-40B8-B508-5198AF2209BC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FF3B0F1B-3BE0-40B8-B508-5198AF2209BC}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal