Skip to content

Commit 67a07e9

Browse files
authored
Merge pull request #83 from msft-takend/main
Dotnet 8 udpdate and Benchmarking
2 parents 5f8db20 + 8f33f3f commit 67a07e9

14 files changed

+787
-65
lines changed

.github/workflows/benchmark.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Benchmark
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
benchmark:
11+
name: Run Benchmarks
12+
runs-on: windows-latest
13+
strategy:
14+
matrix:
15+
dotnet-version: [8.x, 9.x]
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: actions/setup-dotnet@v4
19+
with:
20+
dotnet-version: ${{matrix.dotnet-version}}
21+
dotnet-quality: "preview"
22+
- name: Run benchmark
23+
working-directory: src/FftSharp.Benchmark
24+
run: dotnet run --exporters json --filter '*'

.github/workflows/ci.yaml

+5-7
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@ jobs:
1414
runs-on: windows-latest
1515
steps:
1616
- name: 🛒 Checkout
17-
uses: actions/checkout@v3
18-
- name: ✨ Setup .NET 6
19-
uses: actions/setup-dotnet@v3
20-
with:
21-
dotnet-version: "6.0.x"
17+
uses: actions/checkout@v4
18+
- name: ✨ Setup .NET
19+
uses: actions/setup-dotnet@v4
2220
- name: 🚚 Restore
2321
run: dotnet restore src
2422
- name: 🛠️ Build
25-
run: dotnet build src --configuration Release --no-restore
23+
run: dotnet build src
2624
- name: 🧪 Test
27-
run: dotnet test src --configuration Release --no-build
25+
run: dotnet test src

.github/workflows/package.yaml

+7-17
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,20 @@ jobs:
99
runs-on: windows-latest
1010
steps:
1111
- name: 🛒 Checkout
12-
uses: actions/checkout@v3
13-
- name: ✨ Setup .NET 6
14-
uses: actions/setup-dotnet@v3
15-
with:
16-
dotnet-version: "6.0.x"
12+
uses: actions/checkout@v4
13+
- name: ✨ Setup .NET
14+
uses: actions/setup-dotnet@v4
1715
- name: 🚚 Restore
1816
run: dotnet restore src
1917
- name: 🛠️ Build
20-
run: dotnet build src --configuration Release --no-restore
18+
run: dotnet build src
2119
- name: 🧪 Test
22-
run: dotnet test src --configuration Release --no-build
20+
run: dotnet test src
2321
- name: 📦 Pack
24-
run: dotnet pack src --configuration Release --no-build
25-
- name: 💾 Store
26-
uses: actions/upload-artifact@v2
27-
with:
28-
name: Packages
29-
retention-days: 1
30-
path: |
31-
src/FftSharp/bin/Release/*.nupkg
32-
src/FftSharp/bin/Release/*.snupkg
22+
run: dotnet pack src
3323
- name: 🔑 Secret
3424
uses: nuget/setup-nuget@v1
3525
with:
3626
nuget-api-key: ${{ secrets.NUGET_API_KEY }}
3727
- name: 🚀 Deploy
38-
run: nuget push "src\FftSharp\bin\Release\*.nupkg" -SkipDuplicate -Source https://api.nuget.org/v3/index.json
28+
run: nuget push "src\FftSharp\bin\Release\*.nupkg" -SkipDuplicate -Source https://api.nuget.org/v3/index.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace FftSharp.Benchmark;
2+
3+
public static class BenchmarkLoadData
4+
{
5+
public static double[] Double(string fileName) =>
6+
File.ReadLines(fileName)
7+
.Where(x => !x.StartsWith('#') && x.Length > 1)
8+
.Select(x => double.Parse(x))
9+
.ToArray();
10+
11+
public static System.Numerics.Complex[] Complex(string fileName) =>
12+
File.ReadLines(fileName)
13+
.Select(x => x.Trim('(').Trim(')').Trim('j'))
14+
.Select(x => x.Replace("-", " -").Replace("+", " +").Trim())
15+
.Select(x => new System.Numerics.Complex(double.Parse(x.Split(' ')[0]), double.Parse(x.Split(' ')[1])))
16+
.ToArray();
17+
}
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Benchmarking
2+
3+
## Benchmarking FFTSharp
4+
5+
To run the benchmarks navigate to the `src/FftSharp.Benchmark` directory and run the following command:
6+
7+
```bash
8+
dotnet run -c Release
9+
```
10+
11+
## Results 12/20/2023
12+
13+
### BluesteinSizeBenchmark
14+
```
15+
BenchmarkDotNet v0.13.11, Windows 11 (10.0.22631.2861/23H2/2023Update/SunValley3)
16+
Intel Core i7-1065G7 CPU 1.30GHz, 1 CPU, 8 logical and 4 physical cores
17+
.NET SDK 8.0.100
18+
[Host] : .NET 6.0.25 (6.0.2523.51912), X64 RyuJIT AVX2
19+
.NET 6.0 : .NET 6.0.25 (6.0.2523.51912), X64 RyuJIT AVX2
20+
.NET 8.0 : .NET 8.0.0 (8.0.23.53103), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI
21+
```
22+
| Method | Job | Runtime | DataLength | Mean | Error | StdDev | Gen0 | Gen1 | Gen2 | Allocated |
23+
|---------- |--------- |--------- |----------- |-------------:|-------------:|-------------:|---------:|---------:|---------:|------------:|
24+
| **Bluestein** | **.NET 6.0** | **.NET 6.0** | **100** | **26.40 μs** | **0.401 μs** | **0.375 μs** | **7.1716** | **0.0305** | **-** | **29.36 KB** |
25+
| Bluestein | .NET 8.0 | .NET 8.0 | 100 | 24.97 μs | 0.321 μs | 0.284 μs | 7.1716 | - | - | 29.36 KB |
26+
| **Bluestein** | **.NET 6.0** | **.NET 6.0** | **1000** | **247.14 μs** | **3.809 μs** | **3.181 μs** | **58.1055** | **16.1133** | **-** | **239.49 KB** |
27+
| Bluestein | .NET 8.0 | .NET 8.0 | 1000 | 239.35 μs | 4.046 μs | 3.379 μs | 58.1055 | 16.3574 | - | 239.49 KB |
28+
| **Bluestein** | **.NET 6.0** | **.NET 6.0** | **10000** | **5,426.03 μs** | **88.896 μs** | **102.372 μs** | **984.3750** | **984.3750** | **984.3750** | **3641.08 KB** |
29+
| Bluestein | .NET 8.0 | .NET 8.0 | 10000 | 5,348.21 μs | 103.018 μs | 86.025 μs | 984.3750 | 984.3750 | 984.3750 | 3641.04 KB |
30+
| **Bluestein** | **.NET 6.0** | **.NET 6.0** | **100000** | **84,122.15 μs** | **1,655.385 μs** | **2,374.104 μs** | **833.3333** | **833.3333** | **833.3333** | **29749.57 KB** |
31+
| Bluestein | .NET 8.0 | .NET 8.0 | 100000 | 83,047.50 μs | 1,654.760 μs | 2,718.818 μs | 666.6667 | 666.6667 | 666.6667 | 29751.45 KB |
32+
33+
### FftBenchmark
34+
```
35+
BenchmarkDotNet v0.13.11, Windows 11 (10.0.22631.2861/23H2/2023Update/SunValley3)
36+
Intel Core i7-1065G7 CPU 1.30GHz, 1 CPU, 8 logical and 4 physical cores
37+
.NET SDK 8.0.100
38+
[Host] : .NET 6.0.25 (6.0.2523.51912), X64 RyuJIT AVX2
39+
.NET 6.0 : .NET 6.0.25 (6.0.2523.51912), X64 RyuJIT AVX2
40+
.NET 8.0 : .NET 8.0.0 (8.0.23.53103), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI
41+
```
42+
| Method | Job | Runtime | Mean | Error | StdDev | Gen0 | Gen1 | Allocated |
43+
|------------------------ |--------- |--------- |----------:|---------:|---------:|--------:|--------:|----------:|
44+
| FFT_Forward | .NET 6.0 | .NET 6.0 | 41.47 μs | 0.722 μs | 0.676 μs | 1.9531 | - | 8.02 KB |
45+
| FFT_ForwardReal | .NET 6.0 | .NET 6.0 | 42.72 μs | 0.715 μs | 0.669 μs | 2.9297 | - | 12.06 KB |
46+
| FFT_BluesteinComparason | .NET 6.0 | .NET 6.0 | 233.21 μs | 3.444 μs | 3.053 μs | 54.4434 | 15.3809 | 224.24 KB |
47+
| FFT_Forward | .NET 8.0 | .NET 8.0 | 41.08 μs | 0.749 μs | 0.585 μs | 1.9531 | - | 8.02 KB |
48+
| FFT_ForwardReal | .NET 8.0 | .NET 8.0 | 41.79 μs | 0.788 μs | 0.698 μs | 2.9297 | - | 12.06 KB |
49+
| FFT_BluesteinComparason | .NET 8.0 | .NET 8.0 | 223.61 μs | 4.330 μs | 4.633 μs | 54.4434 | 15.3809 | 224.23 KB |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using BenchmarkDotNet.Attributes;
2+
using BenchmarkDotNet.Jobs;
3+
using MathNet.Numerics;
4+
namespace FftSharp.Benchmark;
5+
6+
[MemoryDiagnoser]
7+
[SimpleJob(RuntimeMoniker.Net60)]
8+
[SimpleJob(RuntimeMoniker.Net80)]
9+
public class BluesteinSizeBenchmark
10+
{
11+
private double[] Sample;
12+
[Params(100, 1000, 10_000, 100_000)]
13+
public int DataLength { get ; set; }
14+
public double Frequency = 60;
15+
public double SampleRate = 1000;
16+
17+
[GlobalSetup]
18+
public void BluesteinSizeBenchmarkSetup()
19+
{
20+
this.Sample = Generate.Sinusoidal(this.DataLength, this.SampleRate, this.Frequency, 1);
21+
if(this.Sample.Length != this.DataLength)
22+
{
23+
throw new Exception("Sample length does not match DataLength");
24+
}
25+
}
26+
27+
[Benchmark]
28+
public void Bluestein()
29+
{
30+
var something = Experimental.Bluestein(this.Sample);
31+
}
32+
33+
}
34+
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using BenchmarkDotNet.Attributes;
2+
using BenchmarkDotNet.Jobs;
3+
4+
namespace FftSharp.Benchmark;
5+
[SimpleJob(RuntimeMoniker.Net60)]
6+
[SimpleJob(RuntimeMoniker.Net80)]
7+
[MemoryDiagnoser]
8+
public class FftBenchmark
9+
{
10+
private double[] Sample;
11+
12+
[GlobalSetup]
13+
public void FftBenchmarkSetup()
14+
{
15+
this.Sample = BenchmarkLoadData.Double("sample.txt");
16+
}
17+
18+
[Benchmark]
19+
public void FFT_Forward()
20+
{
21+
var something = FFT.Forward(this.Sample);
22+
}
23+
24+
[Benchmark]
25+
public void FFT_ForwardReal()
26+
{
27+
var something = FFT.ForwardReal(this.Sample);
28+
}
29+
30+
[Benchmark]
31+
public void FFT_BluesteinComparason()
32+
{
33+
var something = Experimental.Bluestein(this.Sample);
34+
}
35+
}
36+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<NoWarn>$(NoWarn);CA1018;CA5351;CA1825;CA8618</NoWarn>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="BenchmarkDotNet" Version="0.13.11" />
12+
<PackageReference Include="BenchmarkDotNet.Annotations" Version="0.13.11" />
13+
<PackageReference Include="MathNet.Numerics" Version="5.0.0" />
14+
</ItemGroup>
15+
<ItemGroup Condition=" '$(TargetFrameworkIdentifier)' == '.NETFramework' ">
16+
<Reference Include="System.Reflection" />
17+
<PackageReference Include="System.Memory" Version="4.5.5" />
18+
</ItemGroup>
19+
<ItemGroup>
20+
<ProjectReference Include="..\FftSharp\FftSharp.csproj" />
21+
</ItemGroup>
22+
23+
<ItemGroup>
24+
<None Update="sample.txt">
25+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
26+
</None>
27+
</ItemGroup>
28+
29+
</Project>

src/FftSharp.Benchmark/Program.cs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using BenchmarkDotNet.Configs;
2+
using BenchmarkDotNet.Environments;
3+
using BenchmarkDotNet.Jobs;
4+
using BenchmarkDotNet.Running;
5+
6+
namespace FftSharp.Benchmark;
7+
8+
public class Program
9+
{
10+
static void Main(string[] args)
11+
{
12+
Console.WriteLine("FftSharp Benchmarks!");
13+
BenchmarkRunner.Run<FftBenchmark>();
14+
BenchmarkRunner.Run<BluesteinSizeBenchmark>();
15+
}
16+
}

0 commit comments

Comments
 (0)