Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to .NET9 & Memory Improvements #5

Merged
merged 14 commits into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 37 additions & 91 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,119 +2,65 @@ name: Build and Test

on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]

jobs:

build-and-test:
name: Build and test

strategy:
matrix:
os: [ubuntu-latest]
#os: [ubuntu-latest, windows-latest, macos-latest]
os: [ubuntu-latest]
#os: [ubuntu-latest, windows-latest, macos-latest]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2

- uses: actions/checkout@v2

- name: Setup .NET Core 2.1
uses: actions/setup-dotnet@v1
with:
dotnet-version: 2.1.x
- name: Setup .NET Core 3.1
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.x
- name: Setup .NET Core 5.0
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x

- name: Restore dependencies
run: dotnet restore
- name: Setup .NET Core 9.0
uses: actions/setup-dotnet@v1
with:
dotnet-version: 9.0.x

- name: Build
run: dotnet build --no-restore
- name: Restore dependencies
run: dotnet restore

- name: Test with dotnet
run: dotnet test --no-restore --verbosity normal --logger trx --results-directory "TestResults-${{ matrix.os }}"
- name: Build
run: dotnet build --no-restore

- name: Upload dotnet test results
uses: actions/upload-artifact@v2
with:
name: dotnet-results-${{ matrix.os }}
path: TestResults-${{ matrix.os }}
# Use always() to always run this step to publish test results when there are test failures
if: ${{ always() }}


sonar:
runs-on: windows-latest
needs: build-and-test
steps:
- name: Test with dotnet
run: dotnet test --no-restore --verbosity normal --logger trx --results-directory "TestResults-${{ matrix.os }}"

- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 1.11
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Cache SonarCloud packages
uses: actions/cache@v1
with:
path: ~\sonar\cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache SonarCloud scanner
id: cache-sonar-scanner
uses: actions/cache@v1
with:
path: .\.sonar\scanner
key: ${{ runner.os }}-sonar-scanner
restore-keys: ${{ runner.os }}-sonar-scanner
- name: Install SonarCloud scanner
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
shell: powershell
run: |
New-Item -Path .\.sonar\scanner -ItemType Directory
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
shell: powershell
run: |
.\.sonar\scanner\dotnet-sonarscanner begin /k:"keesschollaart81_SortCS" /o:"keesschollaart81" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io"
dotnet build
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}"
- name: Upload dotnet test results
uses: actions/upload-artifact@v4
with:
name: dotnet-results-${{ matrix.os }}
path: TestResults-${{ matrix.os }}
# Use always() to always run this step to publish test results when there are test failures
if: ${{ always() }}

deploy:
runs-on: ubuntu-latest
needs: build-and-test
steps:
- uses: actions/checkout@v2

- name: Setup .NET Core 9.0
uses: actions/setup-dotnet@v1
with:
dotnet-version: 9.0.x

- uses: actions/checkout@v2
- name: Restore dependencies
run: dotnet restore
working-directory: src/SortCS

- name: Setup .NET Core 5.0
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x

- name: Restore dependencies
run: dotnet restore
working-directory: src/SortCS

- name: Build
run: dotnet build -c Release --no-restore
working-directory: src/SortCS
- name: Build
run: dotnet build -c Release --no-restore
working-directory: src/SortCS

- name: Build
run: dotnet pack -c Release --no-restore
working-directory: src/SortCS

- name: Build
run: dotnet pack -c Release --no-restore
working-directory: src/SortCS
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:
- name: Set VERSION variable from tag
run: echo "VERSION=${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_ENV

- name: Setup .NET Core 5.0
- name: Setup .NET Core 9.0
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
dotnet-version: 9.0.x

- name: Build
working-directory: src/SortCS
Expand Down
9 changes: 9 additions & 0 deletions SortCS.sln
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
LICENSE = LICENSE
README.md = README.md
.github\workflows\release.yml = .github\workflows\release.yml
sonar-project.properties = sonar-project.properties
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SortCS.Tests", "src\SortCS.Tests\SortCS.Tests.csproj", "{13002E85-6B03-49DA-9700-906A24692C98}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SortCS.Benchmarks", "src\SortCS.Benchmarks\SortCS.Benchmarks.csproj", "{9A2468E6-4556-4C7C-8D29-996200A10EF3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -38,11 +41,17 @@ Global
{13002E85-6B03-49DA-9700-906A24692C98}.Debug|Any CPU.Build.0 = Debug|Any CPU
{13002E85-6B03-49DA-9700-906A24692C98}.Release|Any CPU.ActiveCfg = Release|Any CPU
{13002E85-6B03-49DA-9700-906A24692C98}.Release|Any CPU.Build.0 = Release|Any CPU
{9A2468E6-4556-4C7C-8D29-996200A10EF3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9A2468E6-4556-4C7C-8D29-996200A10EF3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9A2468E6-4556-4C7C-8D29-996200A10EF3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9A2468E6-4556-4C7C-8D29-996200A10EF3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8C31716C-280A-44DD-ADAB-E48CEDFBF779}
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
EndGlobalSection
EndGlobal
43 changes: 19 additions & 24 deletions analyzers.targets
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Shared analyzers -->
<!-- Shared analyzers -->

<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="5.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<PackageReference Include="SonarAnalyzer.CSharp" Version="8.19.0.28253">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="9.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>

<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.333">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="AsyncFixer" Version="1.5.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="SonarAnalyzer.CSharp" Version="10.4.0.108396">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>

<!-- <PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.333">-->
<!-- <PrivateAssets>all</PrivateAssets>-->
<!-- <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>-->
<!-- </PackageReference>-->

</ItemGroup>
</ItemGroup>

</Project>
Binary file modified resources/logo.psd
Binary file not shown.
16 changes: 16 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
sonar.projectKey=keesschollaart81_SortCS
sonar.organization=keesschollaart81

# This is the name and version displayed in the SonarCloud UI.
sonar.projectName=SortCS
#sonar.projectVersion=1.0

# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
sonar.sources=.

# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8

# Exclusions
sonar.exclusions=**/Benchmarks/**,**/obj/**,**/*.dll
sonar.coverage.exclusions=**/*.Tests.cs,**/*.Tests/**
52 changes: 52 additions & 0 deletions src/SortCS.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using SortCS;
using System.Drawing;

BenchmarkRunner.Run<SortCSBenchmarks>();

[MemoryDiagnoser]
public class SortCSBenchmarks
{
private ITracker? _tracker;
private List<RectangleF[]>? _frames;

[GlobalSetup]
public void Setup()
{
_tracker = new SortTracker();
_frames = GenerateTestFrames(100, 10);
}

[Benchmark]
public void TrackMultipleFrames()
{
foreach (var frame in _frames ?? [])
{
_tracker!.Track(frame);
}
}

private List<RectangleF[]> GenerateTestFrames(int numFrames, int objectsPerFrame)
{
var random = new Random(42);
var frames = new List<RectangleF[]>();

for (var i = 0; i < numFrames; i++)
{
var objects = new RectangleF[objectsPerFrame];
for (var j = 0; j < objectsPerFrame; j++)
{
objects[j] = new RectangleF(
random.Next(0, 1000),
random.Next(0, 1000),
random.Next(50, 200),
random.Next(50, 200)
);
}
frames.Add(objects);
}

return frames;
}
}
17 changes: 17 additions & 0 deletions src/SortCS.Benchmarks/SortCS.Benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\SortCS\SortCS.csproj" />
</ItemGroup>
</Project>
Loading
Loading