Skip to content

Commit

Permalink
Feature/dotnet6 p5 bigint (#2)
Browse files Browse the repository at this point in the history
net6 - bigint parser benchmark
  • Loading branch information
djfoxer authored Jul 11, 2021
1 parent f7e394a commit 46820e6
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 18 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ public bool StringStartsWith()
}
```

### BigInt:
```csharp
// _bingIntToParse = string.Concat(Enumerable.Repeat("654719003", 50));
public BigInteger ParseBigInt() => BigInteger.Parse(_bingIntToParse);
```

### Deserialize:
```csharp

Expand Down Expand Up @@ -126,9 +133,9 @@ using (var fileStream = new FileStream(_fileName, FileMode.Create, FileAccess.Wr
}
}
```
# Benchmark experiment #3 [07.06.2021]:
# Benchmark experiment #3 [11.07.2021]:

.NET 6 Preview 4 is now available. New SDK brings huge FileStream performance boost (up to 4x faster ), check it out: **[.NET 6 FileStream Boost Details](doc/Benchmark_DotNet6.md)**.
.NET 6 Preview 4 is now available. New SDK brings huge performance boost in FileStream (up to 4x faster) and BigInteger parser (up to 16x faster), check it out: **[.NET 6 Boost Details](doc/Benchmark_DotNet6.md)**.

![logo](img/ben3.png)

Expand Down
28 changes: 27 additions & 1 deletion doc/Benchmark_DotNet6.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# .NET 6 FileStream Performance Boost
# .NET 6 Performance Boost

## FileStream results

``` ini

Expand Down Expand Up @@ -26,3 +28,27 @@ Intel Core i7-4702MQ CPU 2.20GHz (Haswell), 1 CPU, 8 logical and 4 physical core
| WriteAsync | .NET Framework 4.8 | .NET Framework 4.8 | 17.969 ms | 0.4371 ms | 1.2541 ms | 17.220 ms | 1.00 | 0.00 |

![Chart](../img/cmp_3_1.png)

## BigInteger parser results

``` ini

BenchmarkDotNet=v0.13.0, OS=Windows 10.0.19043.1083 (21H1/May2021Update)
Intel Core i7-4702MQ CPU 2.20GHz (Haswell), 1 CPU, 8 logical and 4 physical cores
.NET SDK=6.0.100-preview.5.21302.13
[Host] : .NET 5.0.5 (5.0.521.16609), X64 RyuJIT
.NET 5.0 : .NET 5.0.7 (5.0.721.25508), X64 RyuJIT
.NET 6.0 : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT
.NET Core 3.1 : .NET Core 3.1.16 (CoreCLR 4.700.21.26205, CoreFX 4.700.21.26205), X64 RyuJIT
.NET Framework 4.8 : .NET Framework 4.8 (4.8.4390.0), X64 RyuJIT


```
| Method | Job | Runtime | Mean | Error | StdDev | Ratio |
|------------ |------------------- |------------------- |----------:|----------:|----------:|------:|
| ParseBigInt | .NET 5.0 | .NET 5.0 | 71.578 μs | 0.7426 μs | 0.6947 μs | 0.76 |
| ParseBigInt | .NET 6.0 | .NET 6.0 | 5.538 μs | 0.0555 μs | 0.0520 μs | 0.06 |
| ParseBigInt | .NET Core 3.1 | .NET Core 3.1 | 90.957 μs | 0.4245 μs | 0.3970 μs | 0.97 |
| ParseBigInt | .NET Framework 4.8 | .NET Framework 4.8 | 93.959 μs | 0.8641 μs | 0.8082 μs | 1.00 |

![Chart](../img/cmp_3_2.png)
Binary file added img/cmp_3_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion scripts/publish.bat
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ dotnet publish "../src/djfoxer.PerformanceDotNet/djfoxer.PerformanceDotNet.App"
REM copy src
Xcopy /S /I /E /Q "../src/djfoxer.PerformanceDotNet" "artifact/bin" /exclude:xcopy_exclude.txt
REM create run.bat script
echo .\bin\exe\djfoxer.PerformanceDotNet.App.exe > artifact/run.bat
echo .\bin\exe\djfoxer.PerformanceDotNet.App.exe %%^* > artifact/run.bat
REM open artifact folder
cd artifact
REM get exe version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net6.0;net5.0;netcoreapp3.1;net48</TargetFrameworks>
<Version>1.2.0</Version>
<Version>1.2.2</Version>
<Platforms>x64</Platforms>
<StartupObject>djfoxer.PerformanceDotNet.App.Program</StartupObject>
<Authors>djfoxer</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ namespace djfoxer.PerformanceDotNet.Common
{
public class FileStreamBenchmark : BaseBenchmark
{
static int FileSize = 1_000_000;
static string _fileName = "file.txt";
byte[] _buffer = new byte[8_000];
const int FileSize = 1_000_000;
const string _fileName = "file.txt";
readonly byte[] _buffer = new byte[8_000];

[GlobalSetup(Target = nameof(ReadAsync))]
public void SetupRead() => File.WriteAllBytes(_fileName, new byte[FileSize]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,27 @@ namespace djfoxer.PerformanceDotNet.Common

public class MainBenchmark : BaseBenchmark
{
IEnumerable<int> _tenMillionToZero = Enumerable.Range(0, 10_000_000).Reverse();
byte[] _rawBytes = new byte[100 * 1024 * 1024];
HashAlgorithm _sha = SHA256.Create();
static string StringToTest = "abcdefghijklmnopqrstuvwxyz";
List<BookToSerialize> _books = null;
readonly IEnumerable<int> _tenMillionToZero = Enumerable.Range(0, 10_000_000).Reverse();
readonly byte[] _rawBytes = new byte[100 * 1024 * 1024];
readonly HashAlgorithm _sha = SHA256.Create();
const string StringToTest = "abcdefghijklmnopqrstuvwxyz";
readonly List<BookToSerialize> _books = new List<BookToSerialize>();

[GlobalSetup]
public void BenchmarkSetup()
{
//Sha256
for (int index = 0; index < _rawBytes.Length; index++) _rawBytes[index] = (byte)index;

_books = new List<BookToSerialize>();
//Deserialize
_books.Clear();
for (int i = 0; i < 1_00000; i++)
{
string id = i.ToString();
_books.Add(new BookToSerialize { Name = id, Id = id });
}
}

[Benchmark]
public DayOfWeek EnumParse() => (DayOfWeek)Enum.Parse(typeof(DayOfWeek), "Thursday");

[Benchmark]
public int LinqOrderBySkipFirst()
{
Expand Down Expand Up @@ -67,5 +66,7 @@ public object Deserialize()

return formatter.Deserialize(mem);
}


}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using BenchmarkDotNet.Attributes;
using djfoxer.PerformanceDotNet.Common.Helpers;
using System;
using System.Linq;
using System.Numerics;

namespace djfoxer.PerformanceDotNet.Common
{
public class ParseBenchmark : BaseBenchmark
{
string _bingIntToParse;
[GlobalSetup(Target = nameof(ParseBigInt))]
public void SetupRead() => _bingIntToParse = string.Concat(Enumerable.Repeat("654719003", 50));

[Benchmark]
public DayOfWeek EnumParse() => (DayOfWeek)Enum.Parse(typeof(DayOfWeek), "Thursday");

[Benchmark]
public BigInteger ParseBigInt() => BigInteger.Parse(_bingIntToParse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Platforms>x64</Platforms>
<Version>1.2.0</Version>
<Version>1.2.2</Version>
<Authors>djfoxer</Authors>
<Company>djfoxer</Company>
</PropertyGroup>
Expand Down

0 comments on commit 46820e6

Please sign in to comment.