Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</PropertyGroup>

<ItemGroup>
<None Include="..\..\assets\logo.64x64.png" Pack="true" PackagePath="" />
<None Include="..\..\assets\logo.64x64.png" Pack="true" PackagePath="" Condition="'$(IsPackable)' == 'true'"/>
</ItemGroup>

<ItemGroup>
Expand Down
9 changes: 9 additions & 0 deletions src/GraphQLParser.Benchmarks/Benchmarks/IBenchmark.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace GraphQLParser.Benchmarks
{
internal interface IBenchmark
{
void GlobalSetup();

void Run();
}
}
44 changes: 44 additions & 0 deletions src/GraphQLParser.Benchmarks/Benchmarks/LexerBenchmark.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System.Collections.Generic;
using BenchmarkDotNet.Attributes;

namespace GraphQLParser.Benchmarks
{
[MemoryDiagnoser]
public class LexerBenchmark : IBenchmark
{
private string _escapes = null!;
private string _kitchen = null!;
private string _github = null!;

[GlobalSetup]
public void GlobalSetup()
{
_escapes = "query_with_many_escape_symbols".ReadGraphQLFile();
_kitchen = "kitchenSink".ReadGraphQLFile();
_github = "github".ReadGraphQLFile();
}

[Benchmark]
[ArgumentsSource(nameof(Queries))]
public void Lex(string query)
{
var lexer = new Lexer();
var source = new Source(query);
int resetPosition = 0;
Token token;
while ((token = lexer.Lex(source, resetPosition)).Kind != TokenKind.EOF)
{
resetPosition = token.End;
}
}

public IEnumerable<string> Queries()
{
yield return _escapes;
yield return _kitchen;
yield return _github;
}

void IBenchmark.Run() => Lex(_github);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using BenchmarkDotNet.Attributes;
using System.Collections.Generic;
using BenchmarkDotNet.Attributes;

namespace GraphQLParser.Benchmarks
{
[MemoryDiagnoser]
[RPlotExporter, CsvMeasurementsExporter]
public class ParserBenchmark
//[RPlotExporter, CsvMeasurementsExporter]
public class ParserBenchmark : IBenchmark
{
private ILexemeCache? _serial;
private ILexemeCache? _concurrent;
Expand Down Expand Up @@ -44,10 +44,12 @@ public void Concurrent(Query query)
public IEnumerable<Query> Queries()
{
yield return new Query { Name = "Simple", Text = SMALL_QUERY };
yield return new Query { Name = "Schema", Text = INTROSPECTION_QUERY };
yield return new Query { Name = "Schema", Text = _introspectionQuery };
yield return new Query { Name = "Params", Text = PARAMS_QUERY };
}

void IBenchmark.Run() => Parse(new Query { Name = "Simple", Text = SMALL_QUERY });

public struct Query
{
public string Text;
Expand All @@ -57,105 +59,6 @@ public struct Query

private const string SMALL_QUERY = "query test { field1 field2(id: 5) { name address } field3 }";
private const string PARAMS_QUERY = @"query { something(name: ""one"", names: [""abc"", ""def"", ""klmn"", ""abra"", ""blabla"", ""kadabra"", ""100500""] code: 123, values: [1,2,3,4,5,6,7,8,9,0,10,20,30,40,50,60,70,80,90,100], modified: true, percents: [10.1, 20.2, 30.3, 40.4, 50.5, 60.6, 70.7], mask: [true, false, true, false, true, false], struct: { name: ""tom"", age: 42, height: 1.82, friends: [ { name: ""nik"" }, { name: ""ben"" }]}) }";
private const string INTROSPECTION_QUERY = @"
query IntrospectionQuery {
__schema {
queryType { name }
mutationType { name }
subscriptionType { name }
types {
...FullType
}
directives {
name
description
locations
args {
...InputValue
}
}
}
}

fragment FullType on __Type {
kind
name
description
fields(includeDeprecated: true) {
name
description
args {
...InputValue
}
type {
...TypeRef
}
isDeprecated
deprecationReason
directives {
name
args {
name
value
}
}
}
inputFields {
...InputValue
}
interfaces {
...TypeRef
}
enumValues(includeDeprecated: true) {
name
description
isDeprecated
deprecationReason
}
possibleTypes {
...TypeRef
}
}

fragment InputValue on __InputValue {
name
description
type { ...TypeRef }
defaultValue
}

fragment TypeRef on __Type {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
}
}
}
}
}
}
}
}
";
private static readonly string _introspectionQuery = "introspectionQuery".ReadGraphQLFile();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
using System.IO;
using BenchmarkDotNet.Attributes;
using GraphQLParser.Exceptions;

namespace GraphQLParser.Benchmarks
{
[MemoryDiagnoser]
public class ParserBinaryBenchmark
public class ParserBinaryBenchmark : IBenchmark
{
private string _binaryTest = null!;

[GlobalSetup]
public void GlobalSetup()
{
_binaryTest = "BinaryTest".ReadGraphQLFile();
}

[Benchmark]
public void ParseBinaryFile()
{
try
{
var parser = new Parser(new Lexer());
parser.Parse(new Source(File.ReadAllText("BinaryTest.graphql")));
parser.Parse(new Source(_binaryTest));
}
catch (GraphQLSyntaxErrorException)
{
}
}

void IBenchmark.Run() => ParseBinaryFile();
}
}
Loading