-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [.NET] Add benchmarks * [.NET] Gherkin.Parser: avoid delegate creation * [.NET] GherkinLine.SplitCells: Avoid string allocations * [.NET] Optimize AstNode.subItems handling * [.NET] Remove old Mono workaround and use string.StartsWith with ordinal everywhere * [.NET] Gherkinline.GetTableCells: avoid string concatenation * [.NET] AstBuilder.GetCells: avoid unnesscary enumerator and array collections * [.NET] GherkinDialectProvider.ParseJsonContent: Use SourceCodeGenerator for System.Text.Json * [.NET] GherkinLine.GetTags: avoid calling RegEx
- Loading branch information
Showing
14 changed files
with
435 additions
and
113 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
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,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFrameworks>net8.0;net481</TargetFrameworks> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" /> | ||
<PackageReference Include="System.Collections.Immutable" Version="8.0.0" /> | ||
<PackageReference Include="System.Reflection.Metadata" Version="8.0.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Gherkin\Gherkin.csproj" /> | ||
</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,43 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using Gherkin.Ast; | ||
using System.Text; | ||
|
||
namespace Gherkin.Benchmarks; | ||
|
||
public class GherkingParser | ||
{ | ||
[Params("very_long.feature", "tags.feature")] | ||
public string? FeatureFile { get; set; } | ||
|
||
readonly MemoryStream _TestData = new(); | ||
readonly Parser _ParserReused = new(); | ||
readonly TokenMatcher _TokenMatcher = new(); | ||
StreamReader? _Reader; | ||
|
||
[GlobalSetup] | ||
public void GlobalSetup() | ||
{ | ||
var fullPathToTestFeatureFile = Path.Combine(TestFileProvider.GetTestFileFolder("good"), FeatureFile!); | ||
|
||
using var fileStream = new FileStream(fullPathToTestFeatureFile, FileMode.Open, FileAccess.Read); | ||
|
||
fileStream.CopyTo(_TestData); | ||
|
||
_Reader = new StreamReader(_TestData, Encoding.UTF8, false, 4096, true); | ||
} | ||
|
||
[Benchmark] | ||
public GherkinDocument Parser() | ||
{ | ||
_TestData.Seek(0, SeekOrigin.Begin); | ||
var parser = new Parser(); | ||
return parser.Parse(new TokenScanner(_Reader)); | ||
} | ||
|
||
[Benchmark] | ||
public GherkinDocument ParserReuse() | ||
{ | ||
_TestData.Seek(0, SeekOrigin.Begin); | ||
return _ParserReused.Parse(new TokenScanner(_Reader), _TokenMatcher); | ||
} | ||
} |
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,24 @@ | ||
using BenchmarkDotNet.Configs; | ||
using BenchmarkDotNet.Diagnosers; | ||
using BenchmarkDotNet.Environments; | ||
using BenchmarkDotNet.Jobs; | ||
using BenchmarkDotNet.Running; | ||
|
||
namespace Gherkin.Benchmarks; | ||
|
||
internal class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
#if DEBUG | ||
var config = new DebugInProcessConfig() | ||
#else | ||
var config = DefaultConfig.Instance | ||
.AddJob(Job.Default.WithRuntime(CoreRuntime.Core80)) | ||
.AddJob(Job.Default.WithRuntime(ClrRuntime.Net481)) | ||
#endif | ||
.AddDiagnoser(MemoryDiagnoser.Default) | ||
; | ||
_ = BenchmarkRunner.Run<GherkingParser>(config); | ||
} | ||
} |
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,15 @@ | ||
namespace Gherkin.Benchmarks; | ||
|
||
public class TestFileProvider | ||
{ | ||
public static string GetTestFileFolder(string category) | ||
{ | ||
var inputFolder = Environment.CurrentDirectory; | ||
#if DEBUG | ||
// Artefacts are not created in subdirectories, so we don't need to go any higher. | ||
#elif NET6_0_OR_GREATER | ||
inputFolder = Path.Combine(inputFolder, "..", "..", "..", ".."); | ||
#endif | ||
return Path.GetFullPath(Path.Combine(inputFolder, "..", "..", "..", "..", "..", "testdata", category)); | ||
} | ||
} |
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
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
Oops, something went wrong.