-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- String equality - String hashing - Parser throughput - Added IPV6 support to Host
- Loading branch information
Showing
10 changed files
with
432 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
.vscode/ | ||
.vs/ | ||
.vimspector.json | ||
raw.log | ||
|
||
[Bb]in/ | ||
[Oo]bj/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net5.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="../../src/ThePlague.IRC.Parser/ThePlague.IRC.Parser.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="System.IO.Pipelines" Version="6.0.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Content Include="raw.log" CopyToOutputDirectory="PreserveNewest" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
using System; | ||
using System.Buffers; | ||
using System.IO; | ||
using System.IO.Pipelines; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using System.Diagnostics; | ||
|
||
using ThePlague.Model.Core.Text; | ||
using ThePlague.IRC.Parser; | ||
using ThePlague.IRC.Parser.Tokens; | ||
|
||
namespace IRCParserThroughput | ||
{ | ||
public class Program | ||
{ | ||
private static string _Filename = "raw.log"; | ||
|
||
static async Task Main(string[] args) | ||
{ | ||
#if DEBUG | ||
Console.WriteLine($"Please attach a debugger to process {Environment.ProcessId}..."); | ||
while(!Debugger.IsAttached) | ||
{ | ||
Thread.Sleep(100); | ||
} | ||
#endif | ||
|
||
Stopwatch stopWatch = new Stopwatch(); | ||
using Stream stream = File.OpenRead(_Filename); | ||
PipeReader reader = PipeReader.Create | ||
( | ||
stream, | ||
new StreamPipeReaderOptions(null, 512, 128, true) | ||
); | ||
|
||
ValueTask<ReadResult> vt; | ||
ReadOnlySequence<byte> sequence; | ||
Token message; | ||
long averageTime = 0, maxTime = 0, minTime = 0, time = 0, total = 0; | ||
ReadResult result; | ||
string min = string.Empty, max = string.Empty; | ||
|
||
while(true) | ||
{ | ||
if(!reader.TryRead(out result)) | ||
{ | ||
vt = reader.ReadAsync(); | ||
|
||
if(!vt.IsCompletedSuccessfully) | ||
{ | ||
result = await vt; | ||
} | ||
else | ||
{ | ||
result = vt.Result; | ||
} | ||
} | ||
|
||
if(result.IsCompleted) | ||
{ | ||
break; | ||
} | ||
|
||
sequence = result.Buffer; | ||
|
||
stopWatch.Start(); | ||
if(IRCParser.TryParse | ||
( | ||
in sequence, | ||
out message | ||
)) | ||
{ | ||
stopWatch.Stop(); | ||
|
||
//Console.WriteLine(message.ToUtf8String().ToString()); | ||
|
||
time = stopWatch.ElapsedTicks; | ||
total += time; | ||
|
||
if(averageTime == 0) | ||
{ | ||
averageTime = time; | ||
} | ||
else | ||
{ | ||
averageTime += time; | ||
averageTime /= 2; | ||
} | ||
|
||
if(maxTime == 0 | ||
|| time > maxTime) | ||
{ | ||
maxTime = time; | ||
max = message.ToUtf8String().ToString(); | ||
} | ||
|
||
if(minTime == 0 | ||
|| time < minTime) | ||
{ | ||
minTime = time; | ||
min = message.ToUtf8String().ToString(); | ||
} | ||
|
||
reader.AdvanceTo(message.Sequence.End); | ||
} | ||
else | ||
{ | ||
reader.AdvanceTo(sequence.Start, sequence.End); | ||
} | ||
|
||
stopWatch.Reset(); | ||
} | ||
|
||
reader.Complete(); | ||
|
||
Console.WriteLine($"Average: {averageTime * 1000000 / Stopwatch.Frequency}µs"); | ||
Console.WriteLine($"Max: {maxTime * 1000000 / Stopwatch.Frequency}µs ({max})"); | ||
Console.WriteLine($"Min: {minTime * 1000000 / Stopwatch.Frequency}µs ({min})"); | ||
Console.WriteLine($"Total: {total * 1000 / Stopwatch.Frequency}ms"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Running; | ||
|
||
using ThePlague.Model.Core.Text; | ||
|
||
namespace StringEquality | ||
{ | ||
public static class Program | ||
{ | ||
public static void Main(string[] args) | ||
=> BenchmarkRunner.Run<StringEqualityBenchmark>(args: args); | ||
} | ||
|
||
//[EventPipeProfiler(EventPipeProfile.CpuSampling)] | ||
public class StringEqualityBenchmark | ||
{ | ||
[Benchmark(Baseline = true)] | ||
[ArgumentsSource(nameof(DataUtf16))] | ||
public bool CoreFXEquality(string strA, string strB) | ||
=> string.Equals(strA, strB, StringComparison.OrdinalIgnoreCase); | ||
|
||
[Benchmark] | ||
[ArgumentsSource(nameof(DataUtf8))] | ||
public bool FirstDecodeToUtf16Equality(Utf8String strA, Utf8String strB) | ||
{ | ||
string utf16A = (string)strA; | ||
string utf16B = (string)strB; | ||
|
||
return string.Equals | ||
( | ||
utf16A, | ||
utf16B, | ||
StringComparison.OrdinalIgnoreCase | ||
); | ||
} | ||
|
||
[Benchmark] | ||
[ArgumentsSource(nameof(DataUtf8))] | ||
public bool OrdinalEquals(Utf8String strA, Utf8String strB) | ||
{ | ||
IEqualityComparer<Utf8String> comparer | ||
= BaseUtf8StringComparer.Ordinal; | ||
return comparer.Equals(strA, strB); | ||
} | ||
|
||
[Benchmark] | ||
[ArgumentsSource(nameof(DataUtf8))] | ||
public bool OrdinalIgnoreCaseEquals(Utf8String strA, Utf8String strB) | ||
{ | ||
IEqualityComparer<Utf8String> comparer = | ||
BaseUtf8StringComparer.OrdinalIgnoreCase; | ||
return comparer.Equals(strA, strB); | ||
} | ||
|
||
public static IEnumerable<object[]> DataUtf16() | ||
{ | ||
yield return new object[] { "CaseFolding", "cASEfOLDING" }; | ||
yield return new object[] { "ЯяЯяЯяЯяЯяЯ", "яЯяЯяЯяЯяЯя" }; | ||
} | ||
|
||
public static IEnumerable<object[]> DataUtf8() | ||
{ | ||
yield return new object[] | ||
{ | ||
new Utf8String("CaseFolding"), | ||
new Utf8String("cASEfOLDING") | ||
}; | ||
yield return new object[] | ||
{ | ||
new Utf8String("ЯяЯяЯяЯяЯяЯ"), | ||
new Utf8String("яЯяЯяЯяЯяЯя") | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\ThePlague.Model.Core.Text\ThePlague.Model.Core.Text.csproj" /> | ||
</ItemGroup> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net5.0</TargetFramework> | ||
<LangVersion>Latest</LangVersion> | ||
<TieredCompilation>true</TieredCompilation> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<IncludeBuildOutput>false</IncludeBuildOutput> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<DebugSymbols>true</DebugSymbols> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" Version="0.13.1"/> | ||
</ItemGroup> | ||
|
||
<PropertyGroup> | ||
<DefineConstants>$(DefineConstants);CORECLR</DefineConstants> | ||
<IsWindows Condition="'$(OS)' == 'Windows_NT'">true</IsWindows> | ||
</PropertyGroup> | ||
|
||
<!-- Define non-windows, all configuration properties --> | ||
<PropertyGroup Condition=" '$(IsWindows)' != 'true' "> | ||
<DefineConstants>$(DefineConstants);UNIX</DefineConstants> | ||
</PropertyGroup> | ||
</Project> |
Oops, something went wrong.