Skip to content

chore: Add .NET10 benchmark for CI and .NET 10 Preview installed environment #183

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

Merged
merged 1 commit into from
Jul 8, 2025
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
15 changes: 14 additions & 1 deletion .github/workflows/benchmark.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ on:
type: string
description: Specify benchmark filter text (e,g. Benchmark.ReadMeBenchmark*)
default: '*'
framework:
type: choice
description: Specify target framework for benchmark
default: net9.0
options:
- net9.0
- net10.0

jobs:
benchmark:
Expand All @@ -28,11 +35,17 @@ jobs:
steps:
- uses: Cysharp/Actions/.github/actions/checkout@main
- uses: Cysharp/Actions/.github/actions/setup-dotnet@main

- uses: Cysharp/Actions/.github/actions/setup-dotnet@main
if: ${{ inputs.framework }} == 'net10.0'
with:
dotnet-version: 10.0.x

- run: dotnet build -c Release

- name: Run Benchmarks
working-directory: sandbox/Benchmark
run: dotnet run -c Release --framework net9.0 --no-build --no-launch-profile -- --filter "${{ inputs.filter }}" -- ${{ inputs.config }}
run: dotnet run -c Release --framework ${{ inputs.framework }} --no-build --no-launch-profile -- --filter "${{ inputs.filter }}" -- ${{ inputs.config }}

- name: Upload artifacts
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 #v4.6.1
Expand Down
4 changes: 2 additions & 2 deletions sandbox/Benchmark/Benchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<DefineConstants>$(DefineConstants);DIAGHUB_ENABLE_TRACE_SYSTEM</DefineConstants>
</PropertyGroup>

<!-- Add .NET 10 support when running build inside Visual Studio Preview-->
<PropertyGroup Condition="'$(BuildingInsideVisualStudio)' != '' AND $(VisualStudioDir.Contains('Preview'))">
<!-- Add .NET 10 support if .NET 10 or later version of MSBuild is used. -->
<PropertyGroup Condition="$([MSBuild]::VersionGreaterThanOrEquals('$(NETCoreAppMaximumVersion)','10.0'))">
<TargetFrameworks>net10.0;$(TargetFrameworks)</TargetFrameworks>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public BaseBenchmarkConfig()
// WithOptions(ConfigOptions.GenerateMSBuildBinLog);
}

// Use Job.ShortRun based settings (LaunchCount=1 TargetCount=3 WarmupCount = 3)
// Use Job.ShortRun based settings (LaunchCount=1 IterationCount=3 WarmupCount = 3)
protected virtual Job GetBaseJobConfig() =>
Job.Default
.WithLaunchCount(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ public SystemLinqBenchmarkConfig() : base()

// Add job for ZLinq benchmarks.
AddJob(baseJobConfig.WithToolchain(Constants.DefaultToolchain)
.WithId(Options.HasFlag(ConfigOptions.KeepBenchmarkFiles)
? $"{ZLinqJobId}_" // Needs extra suffix to avoid conflict assembly name. // TODO: It can be removed after BenchmarkDotNet v1.40.1 is release.
: ZLinqJobId));
.WithId(ZLinqJobId));

// Show summary with declared order (Default: execution order)
WithOrderer(new DefaultOrderer(summaryOrderPolicy: SummaryOrderPolicy.Declared));
WithOrderer(new DefaultOrderer(summaryOrderPolicy: SummaryOrderPolicy.Declared, jobOrderPolicy: JobOrderPolicy.Numeric));

// Configure additional settings.
AddConfigurations();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ public TargetFrameworksBenchmarkConfig() : base()
// Note: Run benchmark with `-runtimes` parameters.
AddJob(baseJobConfig.WithToolchain(CsProjCoreToolchain.NetCoreApp80).WithId(".NET 8").AsBaseline());
AddJob(baseJobConfig.WithToolchain(CsProjCoreToolchain.NetCoreApp90).WithId(".NET 9"));
// TODO: Currently BenchmarkDotNet don't support .NET10
//AddJob(baseJobConfig.WithToolchain(CsProjCoreToolchain.NetCoreApp10_0).WithId(".NET 10"));

#if NET10_0_OR_GREATER
AddJob(baseJobConfig.WithToolchain(CsProjCoreToolchain.NetCoreApp10_0).WithId(".NET 10"));
#endif

// Configure additional settings.
AddConfigurations();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,4 +350,12 @@ public static void Consume<T>(this ValueEnumerable<Where<FromEnumerable<T>, T>,
}

#endregion

// ShuffleSkipTake FromArray
public static void Consume<T>(this ValueEnumerable<ShuffleSkipTake<FromArray<T>, T>, T> source, Consumer consumer)
{
using var e = source.Enumerator;
while (e.TryGetNext(out var item))
consumer.Consume(in item);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ namespace Benchmark.ZLinq;

#if !USE_SYSTEM_LINQ || NET10_0_OR_GREATER
[BenchmarkCategory(Categories.Methods.Shuffle)]
[BenchmarkCategory(Categories.Filters.NET10_0_OR_GREATER)]
[BenchmarkCategory(Categories.Filters.SystemLinq_NET10_0_OR_GREATER)]
public partial class ShuffleBenchmark<T> : EnumerableBenchmarkBase_WithBasicTypes<T>
{
private readonly int TakeCount = 100;

[Benchmark]
[BenchmarkCategory(Categories.From.Default)]
public void Shuffle()
Expand All @@ -16,5 +18,27 @@ public void Shuffle()
.Shuffle()
.Consume(consumer);
}

[Benchmark]
[BenchmarkCategory(Categories.From.Default)]
public void ShuffleTake()
{
source.Default
.AsValueEnumerable()
.Shuffle()
.Take(TakeCount)
.Consume(consumer);
}

[Benchmark]
[BenchmarkCategory(Categories.From.Default)]
public void ShuffleTakeLast()
{
source.Default
.AsValueEnumerable()
.Shuffle()
.Take(TakeCount)
.Consume(consumer);
}
}
#endif
4 changes: 4 additions & 0 deletions sandbox/Benchmark/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ namespace Benchmark;

public static class Constants
{
#if NET10_0_OR_GREATER
public static readonly IToolchain DefaultToolchain = CsProjCoreToolchain.NetCoreApp10_0;
#else
public static readonly IToolchain DefaultToolchain = CsProjCoreToolchain.NetCoreApp90;
#endif

public static class DefineConstants
{
Expand Down
8 changes: 7 additions & 1 deletion sandbox/Benchmark/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## How to run benchmarks
## How to run benchmarks

### 1. Visual Studio

Expand Down Expand Up @@ -29,10 +29,16 @@ gh workflow run benchmark.yaml --repo Cysharp/ZLinq --ref $branchName
# Run benchmark with `Default` config with benchmark filter
gh workflow run benchmark.yaml --repo Cysharp/ZLinq --ref $branchName -f filter=Benchmark.ReadMeBenchmark*

# Run benchmark with `TargetFrameworks` config
gh workflow run benchmark.yaml --repo Cysharp/ZLinq --ref $branchName -f config=TargetFrameworks

# Run benchmark with `SystemLinq` config
gh workflow run benchmark.yaml --repo Cysharp/ZLinq --ref $branchName -f config=SystemLinq
```

> [!NOTE]
> When running .NET 10 benchmarks. It need to add `-f framework=net10.0` input parameter

Benchmark results are written to `GitHub Actions Job Summaries`.
And archived as ZIP artifacts.

Expand Down
6 changes: 3 additions & 3 deletions tests/System.Linq.Tests/System.Linq.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
<TestingPlatformShowTestsFailure>true</TestingPlatformShowTestsFailure>
</PropertyGroup>

<!-- Add .NET 10 support when running build inside Visual Studio Preview-->
<PropertyGroup Condition="'$(BuildingInsideVisualStudio)' != '' AND $(VisualStudioDir.Contains('Preview'))">
<TargetFrameworks>$(TargetFrameworks);net10.0</TargetFrameworks>
<!-- Add .NET 10 support if .NET 10 or later version of MSBuild is used. -->
<PropertyGroup Condition="$([MSBuild]::VersionGreaterThanOrEquals('$(NETCoreAppMaximumVersion)','10.0'))">
<TargetFrameworks>net10.0;$(TargetFrameworks)</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions tests/ZLinq.Tests/ZLinq.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
<TargetFrameworks>$(TargetFrameworks);net48</TargetFrameworks>
</PropertyGroup>

<!-- Add .NET 10 support when running build inside Visual Studio Preview-->
<PropertyGroup Condition="'$(BuildingInsideVisualStudio)' != '' AND $(VisualStudioDir.Contains('Preview'))">
<TargetFrameworks>$(TargetFrameworks);net10.0</TargetFrameworks>
<!-- Add .NET 10 support if .NET 10 or later version of MSBuild is used. -->
<PropertyGroup Condition="$([MSBuild]::VersionGreaterThanOrEquals('$(NETCoreAppMaximumVersion)','10.0'))">
<TargetFrameworks>net10.0;$(TargetFrameworks)</TargetFrameworks>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
Expand Down