-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Normen Scheiber <nscheibe@live.com>
- Loading branch information
Showing
10 changed files
with
217 additions
and
24 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
14 changes: 7 additions & 7 deletions
14
...oter.Benchmarks/Base64ParserBenchmarks.cs → ...nchmarks/Base64/Base64ParserBenchmarks.cs
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 |
---|---|---|
@@ -1,40 +1,40 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Mathematics; | ||
|
||
namespace Snapshooter.Benchmarks; | ||
namespace Snapshooter.Benchmarks.Base64; | ||
|
||
[RPlotExporter, MemoryDiagnoser] | ||
[Orderer(BenchmarkDotNet.Order.SummaryOrderPolicy.FastestToSlowest)] | ||
[RankColumn(NumeralSystem.Arabic)] | ||
public class Base64ParserBenchmarks | ||
{ | ||
{ | ||
private static string SmallBase64String = "VGhpcyBpcyBhIHNtYWxsIGJhc2UgNjQgc3RyaW5nIGZvciBiZW5jaG1hcmsgdGVzdGluZw=="; | ||
private static string SmallNoneBase64String = "Thisisasmallbase64stringforbenchmarktesting"; | ||
|
||
private static readonly Base64Parser Base64Parser = new Base64Parser(); | ||
private static readonly Base64Parser _base64Parser = new Base64Parser(); | ||
|
||
[Benchmark(Baseline = true)] | ||
public void ClassicSmallNoneBase64Parse() | ||
{ | ||
Base64Parser.IsBase64FromBase64String(SmallNoneBase64String); | ||
_base64Parser.IsBase64FromBase64String(SmallNoneBase64String); | ||
} | ||
|
||
[Benchmark] | ||
public void ClassicSmallBase64Parse() | ||
{ | ||
Base64Parser.IsBase64FromBase64String(SmallBase64String); | ||
_base64Parser.IsBase64FromBase64String(SmallBase64String); | ||
} | ||
|
||
[Benchmark] | ||
public void NewSmallNoneBase64Parse() | ||
{ | ||
Base64Parser.IsBase64TryFromBase64String(SmallNoneBase64String); | ||
_base64Parser.IsBase64TryFromBase64String(SmallNoneBase64String); | ||
} | ||
|
||
[Benchmark] | ||
public void NewSmallBase64Parse() | ||
{ | ||
Base64Parser.IsBase64TryFromBase64String(SmallBase64String); | ||
_base64Parser.IsBase64TryFromBase64String(SmallBase64String); | ||
} | ||
} | ||
|
53 changes: 53 additions & 0 deletions
53
benchmark/Snapshooter.Benchmarks/DirectoryName/DirectoryNameResolver.cs
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,53 @@ | ||
namespace Snapshooter.Benchmarks.DirectoryName | ||
{ | ||
public class DirectoryNameResolver | ||
{ | ||
public string? GetDirectoryName_PathString(string filenameFullPath) | ||
{ | ||
return Path.GetDirectoryName(filenameFullPath); | ||
} | ||
|
||
public ReadOnlySpan<char> GetDirectoryName_PathAsSpan(string filenameFullPath) | ||
{ | ||
return Path.GetDirectoryName(filenameFullPath.AsSpan()); | ||
} | ||
|
||
public string GetDirectoryName_Split(string filenameFullPath) | ||
{ | ||
var directorySections = filenameFullPath.Split('\\'); | ||
IEnumerable<string>? minusLastSection = directorySections.Take(directorySections.Length - 1); | ||
var directoryName = string.Join("\\", minusLastSection); | ||
|
||
return directoryName; | ||
} | ||
|
||
public string GetDirectoryName_IndexOfString(string filenameFullPath) | ||
{ | ||
string d = filenameFullPath.Remove(filenameFullPath.LastIndexOf('\\')); | ||
|
||
return d; | ||
} | ||
|
||
public ReadOnlySpan<char> GetDirectoryName_IndexOfSpan(string filenameFullPath) | ||
{ | ||
return filenameFullPath.AsSpan(0, filenameFullPath.LastIndexOf('\\')); | ||
} | ||
|
||
public string GetDirectoryName_IndexOfSpanToString(string filenameFullPath) | ||
{ | ||
return filenameFullPath.AsSpan(0, filenameFullPath.LastIndexOf('\\')).ToString(); | ||
} | ||
|
||
public string GetDirectoryName_IndexOfString_Slash(string filenameFullPath) | ||
{ | ||
int index = filenameFullPath.LastIndexOf('\\'); | ||
|
||
if(index < 0) | ||
{ | ||
index = filenameFullPath.LastIndexOf('/'); | ||
} | ||
|
||
return filenameFullPath.Remove(index); | ||
} | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
benchmark/Snapshooter.Benchmarks/DirectoryName/DirectoryNameResolverBenchmarks.cs
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,70 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Mathematics; | ||
|
||
namespace Snapshooter.Benchmarks.DirectoryName; | ||
|
||
[RPlotExporter, MemoryDiagnoser] | ||
[Orderer(BenchmarkDotNet.Order.SummaryOrderPolicy.FastestToSlowest)] | ||
[RankColumn(NumeralSystem.Arabic)] | ||
public class DirectoryNameResolverBenchmarks | ||
{ | ||
private static string absoluteFileNameBackSlash = "C:\\somewhere\\snapshot\\testing\\snapshotfile.snap"; | ||
private static string absoluteFileNameSlash = "C:/somewhere/snapshot/testing/snapshotfile.snap"; | ||
|
||
private static readonly DirectoryNameResolver _directoryNameResolver = new DirectoryNameResolver(); | ||
|
||
[Benchmark(Baseline = true)] | ||
public void GetDirectoryName_PathString() | ||
{ | ||
_directoryNameResolver.GetDirectoryName_PathString(absoluteFileNameBackSlash); | ||
} | ||
|
||
[Benchmark] | ||
public void GetDirectoryName_PathAsSpan() | ||
{ | ||
_directoryNameResolver.GetDirectoryName_PathAsSpan(absoluteFileNameBackSlash); | ||
} | ||
|
||
[Benchmark] | ||
public void GetDirectoryName_Split() | ||
{ | ||
_directoryNameResolver.GetDirectoryName_Split(absoluteFileNameBackSlash); | ||
} | ||
|
||
[Benchmark] | ||
public void GetDirectoryName_IndexOfString() | ||
{ | ||
_directoryNameResolver.GetDirectoryName_IndexOfString(absoluteFileNameBackSlash); | ||
} | ||
|
||
[Benchmark] | ||
public void GetDirectoryName_IndexOfSpan() | ||
{ | ||
_directoryNameResolver.GetDirectoryName_IndexOfSpan(absoluteFileNameBackSlash); | ||
} | ||
|
||
[Benchmark] | ||
public void GetDirectoryName_IndexOfSpanToString() | ||
{ | ||
_directoryNameResolver.GetDirectoryName_IndexOfSpanToString(absoluteFileNameBackSlash); | ||
} | ||
|
||
[Benchmark] | ||
public void GetDirectoryName_PathString_Slash() | ||
{ | ||
_directoryNameResolver.GetDirectoryName_PathString(absoluteFileNameSlash); | ||
} | ||
|
||
[Benchmark] | ||
public void GetDirectoryName_IndexOfString_Slash() | ||
{ | ||
_directoryNameResolver.GetDirectoryName_IndexOfString_Slash(absoluteFileNameSlash); | ||
} | ||
|
||
[Benchmark] | ||
public void GetDirectoryName_IndexOfString_BackSlash() | ||
{ | ||
_directoryNameResolver.GetDirectoryName_IndexOfString_Slash(absoluteFileNameBackSlash); | ||
} | ||
} | ||
|
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
using BenchmarkDotNet.Running; | ||
using Snapshooter.Benchmarks; | ||
|
||
Base64ParserBenchmarks base64ParserBenchmarks = new Base64ParserBenchmarks(); | ||
using Snapshooter.Benchmarks.Base64; | ||
using Snapshooter.Benchmarks.DirectoryName; | ||
|
||
BenchmarkRunner.Run<Base64ParserBenchmarks>(); | ||
BenchmarkRunner.Run<DirectoryNameResolverBenchmarks>(); |
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
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
19 changes: 19 additions & 0 deletions
19
test/Snapshooter.Tests/Extensions/StringExtensionsTests.cs
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 @@ | ||
using Snapshooter.Extensions; | ||
using Xunit; | ||
|
||
namespace Snapshooter.Tests.Extensions | ||
{ | ||
public class StringExtensionsTests | ||
{ | ||
[Theory] | ||
[InlineData("C:\\normal\\path\\with\\filename", "C:\\normal\\path\\with")] | ||
[InlineData("C:/normal/path/with/slash/filename", "C:/normal/path/with/slash")] | ||
[InlineData("/normal/path/with/slash/filename", "/normal/path/with/slash")] | ||
[InlineData("filename", "")] | ||
public void RemoveFilename_RemoveFilenameFromDifferentPath_Success( | ||
string absoluteFilename, string result) | ||
{ | ||
Assert.Equal(result, absoluteFilename.RemoveFilename()); | ||
} | ||
} | ||
} |