Skip to content

Add basic serialize/deserialize benchmarks #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 12, 2019
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
82 changes: 82 additions & 0 deletions Benchmarks/Schema.NET.Benchmarks/Core/BookBenchmark.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
namespace Schema.NET.Benchmarks.Core
{
using System;
using System.Collections.Generic;
using BenchmarkDotNet.Attributes;

public class BookBenchmark : SchemaBenchmarkBase
{
[GlobalSetup]
public void Setup() => this.ConfigureBenchmark(new Book()
{
Id = new Uri("http://example.com/book/1"),
Name = "The Catcher in the Rye",
Author = new Person()
{
Name = "J.D. Salinger"
},
Url = new Uri("http://www.barnesandnoble.com/store/info/offer/JDSalinger"),
WorkExample = new List<ICreativeWork>()
{
new Book()
{
Isbn = "031676948",
BookEdition = "2nd Edition",
BookFormat = BookFormatType.Hardcover,
PotentialAction = new ReadAction()
{
Target = new EntryPoint()
{
UrlTemplate = "http://www.barnesandnoble.com/store/info/offer/0316769487?purchase=true",
ActionPlatform = new List<Uri>()
{
new Uri("https://schema.org/DesktopWebPlatform"),
new Uri("https://schema.org/IOSPlatform"),
new Uri("https://schema.org/AndroidPlatform")
}
},
ExpectsAcceptanceOf = new Offer()
{
Price = 6.99M,
PriceCurrency = "USD",
EligibleRegion = new Country()
{
Name = "US"
},
Availability = ItemAvailability.InStock
}
},
},
new Book()
{
Isbn = "031676947",
BookEdition = "1st Edition",
BookFormat = BookFormatType.EBook,
PotentialAction = new ReadAction()
{
Target = new EntryPoint()
{
UrlTemplate = "http://www.barnesandnoble.com/store/info/offer/031676947?purchase=true",
ActionPlatform = new List<Uri>()
{
new Uri("https://schema.org/DesktopWebPlatform"),
new Uri("https://schema.org/IOSPlatform"),
new Uri("https://schema.org/AndroidPlatform")
}
},
ExpectsAcceptanceOf = new Offer()
{
Price = 1.99M,
PriceCurrency = "USD",
EligibleRegion = new Country()
{
Name = "UK"
},
Availability = ItemAvailability.InStock
}
},
}
}
});
}
}
19 changes: 19 additions & 0 deletions Benchmarks/Schema.NET.Benchmarks/Core/WebsiteBenchmark.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace Schema.NET.Benchmarks.Core
{
using System;
using BenchmarkDotNet.Attributes;

public class WebsiteBenchmark : SchemaBenchmarkBase
{
[GlobalSetup]
public void Setup() => this.ConfigureBenchmark(new WebSite()
{
PotentialAction = new SearchAction()
{
Target = new Uri("http://example.com/search?&q={query}"),
QueryInput = "required"
},
Url = new Uri("https://example.com")
});
}
}
10 changes: 10 additions & 0 deletions Benchmarks/Schema.NET.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Schema.NET.Benchmarks
{
using System;
using BenchmarkDotNet.Running;

internal class Program
{
private static void Main(string[] args) => BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);
}
}
27 changes: 27 additions & 0 deletions Benchmarks/Schema.NET.Benchmarks/Schema.NET.Benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup Label="Build">
<OutputType>Exe</OutputType>
<TargetFrameworks>net472;netcoreapp3.0</TargetFrameworks>
<CodeAnalysisRuleSet>../../MinimumRecommendedRulesWithStyleCop.ruleset</CodeAnalysisRuleSet>
<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup Label="Project References">
<ProjectReference Include="..\..\Source\Schema.NET\Schema.NET.csproj" />
</ItemGroup>

<ItemGroup Label="Package References">
<PackageReference Include="BenchmarkDotNet" Version="0.12.0" />
<!-- See https://github.com/Microsoft/dotnet/tree/master/releases/reference-assemblies -->
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" PrivateAssets="All" Version="1.0.0" />
</ItemGroup>

<ItemGroup Label="Analyzer Package References">
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" PrivateAssets="All" Version="16.4.16" />
<PackageReference Include="StyleCop.Analyzers" PrivateAssets="All" Version="1.1.118" />
</ItemGroup>


</Project>
38 changes: 38 additions & 0 deletions Benchmarks/Schema.NET.Benchmarks/SchemaBenchmarkBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace Schema.NET.Benchmarks
{
using System;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using Newtonsoft.Json;

[KeepBenchmarkFiles]
[MemoryDiagnoser]
[MinColumn]
[MaxColumn]
[HtmlExporter]
[CsvMeasurementsExporter]
[RPlotExporter]
[SimpleJob(RuntimeMoniker.Net472)]
[SimpleJob(RuntimeMoniker.NetCoreApp30)]
public abstract class SchemaBenchmarkBase
{
protected Thing Thing { get; set; }

private Type ThingType { get; set; }

private string SerializedThing { get; set; }

[Benchmark]
public string Serialize() => this.Thing.ToString();

[Benchmark]
public object Deserialize() => JsonConvert.DeserializeObject(this.SerializedThing, this.ThingType);

protected void ConfigureBenchmark(Thing thing)
{
this.Thing = thing;
this.ThingType = this.Thing.GetType();
this.SerializedThing = this.Thing.ToString();
}
}
}
9 changes: 9 additions & 0 deletions Schema.NET.sln
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{0555
.github\SECURITY.md = .github\SECURITY.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Benchmarks", "Benchmarks", "{E25F6292-80CE-45FE-97B0-0EBBF8E1FC6A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Schema.NET.Benchmarks", "Benchmarks\Schema.NET.Benchmarks\Schema.NET.Benchmarks.csproj", "{EA1CBFC3-F165-4811-AA9F-157DEB8E31CC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -73,6 +77,10 @@ Global
{3E75002C-0EF2-4F04-8EC6-CED90BA27AD1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3E75002C-0EF2-4F04-8EC6-CED90BA27AD1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3E75002C-0EF2-4F04-8EC6-CED90BA27AD1}.Release|Any CPU.Build.0 = Release|Any CPU
{EA1CBFC3-F165-4811-AA9F-157DEB8E31CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EA1CBFC3-F165-4811-AA9F-157DEB8E31CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EA1CBFC3-F165-4811-AA9F-157DEB8E31CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EA1CBFC3-F165-4811-AA9F-157DEB8E31CC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -83,6 +91,7 @@ Global
{3E75002C-0EF2-4F04-8EC6-CED90BA27AD1} = {E1B24F25-B8A4-46EE-B7EB-7803DCFC543F}
{566DF0E2-1288-4083-9B55-4C8B69BB1432} = {0555C737-CE4B-4C78-87AB-6296E1E32D01}
{0555C737-CE4B-4C78-87AB-6296E1E32D01} = {7EDFA103-DB69-4C88-9DE4-97ADBF8253A1}
{EA1CBFC3-F165-4811-AA9F-157DEB8E31CC} = {E25F6292-80CE-45FE-97B0-0EBBF8E1FC6A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {73F36209-F8D6-4066-8951-D97729F773CF}
Expand Down