Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic serialize/deserialize benchmarks
- Loading branch information
Showing
6 changed files
with
176 additions
and
0 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
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 | ||
} | ||
}, | ||
} | ||
} | ||
}); | ||
} | ||
} |
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 @@ | ||
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") | ||
}); | ||
} | ||
} |
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,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); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
Benchmarks/Schema.NET.Benchmarks/Schema.NET.Benchmarks.csproj
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,25 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup Label="Build"> | ||
<OutputType>Exe</OutputType> | ||
<TargetFrameworks>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" /> | ||
</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> |
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,31 @@ | ||
namespace Schema.NET.Benchmarks | ||
{ | ||
using System; | ||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Jobs; | ||
using Newtonsoft.Json; | ||
|
||
[SimpleJob(RuntimeMoniker.NetCoreApp30)] | ||
[MemoryDiagnoser] | ||
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(); | ||
} | ||
} | ||
} |
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