Skip to content

Commit

Permalink
Added BenchmarkApp
Browse files Browse the repository at this point in the history
Prepared for building nuget package
Changed target frameworks and retrofitted some code features to support bilding for pre-net5.0 targets
  • Loading branch information
mikhail-barg committed Oct 25, 2021
1 parent 01bdb94 commit 3816243
Show file tree
Hide file tree
Showing 11 changed files with 1,756 additions and 1,634 deletions.
23 changes: 23 additions & 0 deletions src/BenchmarkApp/BenchmarkApp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Content Include="..\..\jsonata-js\test\test-suite\datasets\employees.json" Link="employees.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.1" />
<PackageReference Include="Jsonata.Net.Js" Version="1.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Jsonata.Net.Native\Jsonata.Net.Native.csproj" />
</ItemGroup>

</Project>
55 changes: 55 additions & 0 deletions src/BenchmarkApp/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using Newtonsoft.Json.Linq;
using System;
using System.Diagnostics;
using System.IO;

namespace BenchmarkApp
{
public class Program
{
static void Main(string[] args)
{
BenchmarkRunner.Run<Program>();
}

private readonly string m_data;
private readonly string m_query;
private readonly int m_iterations = 1;

public Program()
{
Console.WriteLine(Directory.GetCurrentDirectory());
this.m_data = File.ReadAllText("employees.json");
this.m_query = @"
{
'name': Employee.FirstName & ' ' & Employee.Surname,
'mobile': Contact.Phone[type = 'mobile'].number
}
";
}

[Benchmark]
public void ProcessNative()
{
Jsonata.Net.Native.JsonataQuery evaluator = new Jsonata.Net.Native.JsonataQuery(this.m_query);
JToken json = JToken.Parse(this.m_data);

for (int i = 0; i < this.m_iterations; ++i)
{
evaluator.Eval(json);
}
}

[Benchmark]
public void ProcessJs()
{
Jsonata.Net.Js.JsonataEngine engine = new Jsonata.Net.Js.JsonataEngine();
for (int i = 0; i < this.m_iterations; ++i)
{
engine.Execute(this.m_query, this.m_data);
}
}
}
}
3,244 changes: 1,622 additions & 1,622 deletions src/Jsonata.Net.Native.TestSuite/TestReport/Jsonata.Net.Native.TestSuite.xml

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions src/Jsonata.Net.Native.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ VisualStudioVersion = 16.0.31702.278
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Jsonata.Net.Native", "Jsonata.Net.Native\Jsonata.Net.Native.csproj", "{BEC03473-EAA4-4202-A57B-1E3A9148635E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jsonata.Net.Native.Tests", "Jsonata.Net.Native.Tests\Jsonata.Net.Native.Tests.csproj", "{BE20B518-F1F6-4F51-95E8-AAA6D98D38C1}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Jsonata.Net.Native.Tests", "Jsonata.Net.Native.Tests\Jsonata.Net.Native.Tests.csproj", "{BE20B518-F1F6-4F51-95E8-AAA6D98D38C1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jsonata.Net.Native.TestSuite", "Jsonata.Net.Native.TestSuite\Jsonata.Net.Native.TestSuite.csproj", "{B9E0AE50-801A-4192-BB56-11C9556CBBD4}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Jsonata.Net.Native.TestSuite", "Jsonata.Net.Native.TestSuite\Jsonata.Net.Native.TestSuite.csproj", "{B9E0AE50-801A-4192-BB56-11C9556CBBD4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BenchmarkApp", "BenchmarkApp\BenchmarkApp.csproj", "{3EA3F316-CAE2-47B4-BCDF-0E6411C50C71}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -27,6 +29,10 @@ Global
{B9E0AE50-801A-4192-BB56-11C9556CBBD4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B9E0AE50-801A-4192-BB56-11C9556CBBD4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B9E0AE50-801A-4192-BB56-11C9556CBBD4}.Release|Any CPU.Build.0 = Release|Any CPU
{3EA3F316-CAE2-47B4-BCDF-0E6411C50C71}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3EA3F316-CAE2-47B4-BCDF-0E6411C50C71}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3EA3F316-CAE2-47B4-BCDF-0E6411C50C71}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3EA3F316-CAE2-47B4-BCDF-0E6411C50C71}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
1 change: 0 additions & 1 deletion src/Jsonata.Net.Native/Eval/ExplicitArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;
using System.Threading.Tasks;

namespace Jsonata.Net.Native.Eval
Expand Down
1 change: 0 additions & 1 deletion src/Jsonata.Net.Native/Eval/Sequence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;
using System.Threading.Tasks;

namespace Jsonata.Net.Native.Eval
Expand Down
7 changes: 7 additions & 0 deletions src/Jsonata.Net.Native/IsExternalInit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#if !NET5_0
//see https://stackoverflow.com/a/64749403/376066
namespace System.Runtime.CompilerServices
{
internal static class IsExternalInit { }
}
#endif
39 changes: 36 additions & 3 deletions src/Jsonata.Net.Native/Jsonata.Net.Native.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,46 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFrameworks>net47;netstandard2.0;net5.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<WarningsAsErrors></WarningsAsErrors>
<DebugType>embedded</DebugType>
<DebugSymbols>true</DebugSymbols>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors />
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Mikhail Barg</Authors>
<Description>.Net native implementation of JSONata query and transformation language</Description>
<Copyright>Copyright © 2021 Mikhail Barg</Copyright>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageProjectUrl>https://github.com/mikhail-barg/jsonata.net.native</PackageProjectUrl>
<PackageIcon>jsonata-button.png</PackageIcon>
<PackageIconUrl />
<PackageTags>jsonata</PackageTags>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<Version>1.0.0-pre1</Version>

<!-- see https://github.com/dotnet/sourcelink/blob/master/docs/README.md#continuousintegrationbuild -->
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
<DeterministicSourcePaths>true</DeterministicSourcePaths>

</PropertyGroup>

<ItemGroup>
<!-- see https://github.com/dotnet/sourcelink/blob/master/docs/README.md#continuousintegrationbuild -->
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
<None Include="..\..\jsonata-button.png" Pack="true" PackagePath="" />
<None Include="..\..\LICENSE" Pack="true" PackagePath="" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Jsonata.Net.Native/Parsing/Lexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private Token scanName()
{
result = this.newToken(TokenType.typeVariable);
}
else if (this.lookupKeyword(this.m_queryText[this.StartPos .. this.CurrentPos], out TokenType tt))
else if (this.lookupKeyword(this.m_queryText.Substring(this.StartPos, this.CurrentPos - this.StartPos), out TokenType tt))
{
result = this.newToken(tt);
}
Expand Down Expand Up @@ -386,7 +386,7 @@ private bool acceptAll(Func<char, bool> isValid)

private Token newToken(TokenType type)
{
Token result = new Token(type, this.m_queryText[this.StartPos..this.CurrentPos], this.StartPos);
Token result = new Token(type, this.m_queryText.Substring(this.StartPos, this.CurrentPos - this.StartPos), this.StartPos);
this.StartPos = this.CurrentPos;
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Jsonata.Net.Native/Parsing/Nodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ public override string ToString()
// A LambdaNode represents a user-defined JSONata function.
internal sealed record LambdaNode(bool isShorthand, List<string> paramNames, LambdaNode.Signature? signature, Node body) : Node
{
internal override LambdaNode optimize()
internal override Node optimize()
{
Node body = this.body.optimize();
if (body != this.body)
Expand Down
4 changes: 2 additions & 2 deletions src/Jsonata.Net.Native/Parsing/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private static Dictionary<TokenType, int> InitBindingPowers()
}
}

foreach (TokenType tt in Enum.GetValues<TokenType>())
foreach (TokenType tt in Enum.GetValues(typeof(TokenType)))
{
if (!results.ContainsKey(tt))
{
Expand All @@ -157,7 +157,7 @@ private static Dictionary<TokenType, int> InitBindingPowers()
// have a binding power.
private static void ValidateBindingPowers(Dictionary<TokenType, int> bps, Dictionary<TokenType, Led> leds)
{
foreach (TokenType tt in Enum.GetValues<TokenType>())
foreach (TokenType tt in Enum.GetValues(typeof(TokenType)))
{
if (leds.ContainsKey(tt) && bps[tt] == 0)
{
Expand Down

0 comments on commit 3816243

Please sign in to comment.