Skip to content

Commit 40bb2d6

Browse files
authored
Merge pull request #183 from filzrev/chore-add-net10-target-when-available
chore: Add .NET10 benchmark for CI and .NET 10 Preview installed environment
2 parents ffaaf44 + d2824bd commit 40bb2d6

File tree

11 files changed

+73
-18
lines changed

11 files changed

+73
-18
lines changed

.github/workflows/benchmark.yaml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ on:
1818
type: string
1919
description: Specify benchmark filter text (e,g. Benchmark.ReadMeBenchmark*)
2020
default: '*'
21+
framework:
22+
type: choice
23+
description: Specify target framework for benchmark
24+
default: net9.0
25+
options:
26+
- net9.0
27+
- net10.0
2128

2229
jobs:
2330
benchmark:
@@ -28,11 +35,17 @@ jobs:
2835
steps:
2936
- uses: Cysharp/Actions/.github/actions/checkout@main
3037
- uses: Cysharp/Actions/.github/actions/setup-dotnet@main
38+
39+
- uses: Cysharp/Actions/.github/actions/setup-dotnet@main
40+
if: ${{ inputs.framework }} == 'net10.0'
41+
with:
42+
dotnet-version: 10.0.x
43+
3144
- run: dotnet build -c Release
3245

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

3750
- name: Upload artifacts
3851
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 #v4.6.1

sandbox/Benchmark/Benchmark.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
<DefineConstants>$(DefineConstants);DIAGHUB_ENABLE_TRACE_SYSTEM</DefineConstants>
1717
</PropertyGroup>
1818

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

sandbox/Benchmark/BenchmarkDotNet/BenchmarkConfigs/BaseBenchmarkConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public BaseBenchmarkConfig()
3535
// WithOptions(ConfigOptions.GenerateMSBuildBinLog);
3636
}
3737

38-
// Use Job.ShortRun based settings (LaunchCount=1 TargetCount=3 WarmupCount = 3)
38+
// Use Job.ShortRun based settings (LaunchCount=1 IterationCount=3 WarmupCount = 3)
3939
protected virtual Job GetBaseJobConfig() =>
4040
Job.Default
4141
.WithLaunchCount(1)

sandbox/Benchmark/BenchmarkDotNet/BenchmarkConfigs/SystemLinqBenchmarkConfig.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,10 @@ public SystemLinqBenchmarkConfig() : base()
2525

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

3230
// Show summary with declared order (Default: execution order)
33-
WithOrderer(new DefaultOrderer(summaryOrderPolicy: SummaryOrderPolicy.Declared));
31+
WithOrderer(new DefaultOrderer(summaryOrderPolicy: SummaryOrderPolicy.Declared, jobOrderPolicy: JobOrderPolicy.Numeric));
3432

3533
// Configure additional settings.
3634
AddConfigurations();

sandbox/Benchmark/BenchmarkDotNet/BenchmarkConfigs/TargetFrameworksBenchmarkConfig.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ public TargetFrameworksBenchmarkConfig() : base()
2020
// Note: Run benchmark with `-runtimes` parameters.
2121
AddJob(baseJobConfig.WithToolchain(CsProjCoreToolchain.NetCoreApp80).WithId(".NET 8").AsBaseline());
2222
AddJob(baseJobConfig.WithToolchain(CsProjCoreToolchain.NetCoreApp90).WithId(".NET 9"));
23-
// TODO: Currently BenchmarkDotNet don't support .NET10
24-
//AddJob(baseJobConfig.WithToolchain(CsProjCoreToolchain.NetCoreApp10_0).WithId(".NET 10"));
23+
24+
#if NET10_0_OR_GREATER
25+
AddJob(baseJobConfig.WithToolchain(CsProjCoreToolchain.NetCoreApp10_0).WithId(".NET 10"));
26+
#endif
2527

2628
// Configure additional settings.
2729
AddConfigurations();

sandbox/Benchmark/BenchmarkDotNet/ExtensionMethods/ConsumerExtensions.UnaryOperations.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,4 +350,12 @@ public static void Consume<T>(this ValueEnumerable<Where<FromEnumerable<T>, T>,
350350
}
351351

352352
#endregion
353+
354+
// ShuffleSkipTake FromArray
355+
public static void Consume<T>(this ValueEnumerable<ShuffleSkipTake<FromArray<T>, T>, T> source, Consumer consumer)
356+
{
357+
using var e = source.Enumerator;
358+
while (e.TryGetNext(out var item))
359+
consumer.Consume(in item);
360+
}
353361
}

sandbox/Benchmark/Benchmarks/ZLinq/MicroBenchmarks/UnaryOperations/ShuffleBenchmark.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ namespace Benchmark.ZLinq;
44

55
#if !USE_SYSTEM_LINQ || NET10_0_OR_GREATER
66
[BenchmarkCategory(Categories.Methods.Shuffle)]
7-
[BenchmarkCategory(Categories.Filters.NET10_0_OR_GREATER)]
7+
[BenchmarkCategory(Categories.Filters.SystemLinq_NET10_0_OR_GREATER)]
88
public partial class ShuffleBenchmark<T> : EnumerableBenchmarkBase_WithBasicTypes<T>
99
{
10+
private readonly int TakeCount = 100;
11+
1012
[Benchmark]
1113
[BenchmarkCategory(Categories.From.Default)]
1214
public void Shuffle()
@@ -16,5 +18,27 @@ public void Shuffle()
1618
.Shuffle()
1719
.Consume(consumer);
1820
}
21+
22+
[Benchmark]
23+
[BenchmarkCategory(Categories.From.Default)]
24+
public void ShuffleTake()
25+
{
26+
source.Default
27+
.AsValueEnumerable()
28+
.Shuffle()
29+
.Take(TakeCount)
30+
.Consume(consumer);
31+
}
32+
33+
[Benchmark]
34+
[BenchmarkCategory(Categories.From.Default)]
35+
public void ShuffleTakeLast()
36+
{
37+
source.Default
38+
.AsValueEnumerable()
39+
.Shuffle()
40+
.Take(TakeCount)
41+
.Consume(consumer);
42+
}
1943
}
2044
#endif

sandbox/Benchmark/Constants.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ namespace Benchmark;
55

66
public static class Constants
77
{
8+
#if NET10_0_OR_GREATER
9+
public static readonly IToolchain DefaultToolchain = CsProjCoreToolchain.NetCoreApp10_0;
10+
#else
811
public static readonly IToolchain DefaultToolchain = CsProjCoreToolchain.NetCoreApp90;
12+
#endif
913

1014
public static class DefineConstants
1115
{

sandbox/Benchmark/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## How to run benchmarks
1+
## How to run benchmarks
22

33
### 1. Visual Studio
44

@@ -29,10 +29,16 @@ gh workflow run benchmark.yaml --repo Cysharp/ZLinq --ref $branchName
2929
# Run benchmark with `Default` config with benchmark filter
3030
gh workflow run benchmark.yaml --repo Cysharp/ZLinq --ref $branchName -f filter=Benchmark.ReadMeBenchmark*
3131
32+
# Run benchmark with `TargetFrameworks` config
33+
gh workflow run benchmark.yaml --repo Cysharp/ZLinq --ref $branchName -f config=TargetFrameworks
34+
3235
# Run benchmark with `SystemLinq` config
3336
gh workflow run benchmark.yaml --repo Cysharp/ZLinq --ref $branchName -f config=SystemLinq
3437
```
3538

39+
> [!NOTE]
40+
> When running .NET 10 benchmarks. It need to add `-f framework=net10.0` input parameter
41+
3642
Benchmark results are written to `GitHub Actions Job Summaries`.
3743
And archived as ZIP artifacts.
3844

tests/System.Linq.Tests/System.Linq.Tests.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
<TestingPlatformShowTestsFailure>true</TestingPlatformShowTestsFailure>
2222
</PropertyGroup>
2323

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

2929
<ItemGroup>

0 commit comments

Comments
 (0)