forked from json-api-dotnet/JsonApiDotNetCore
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request json-api-dotnet#271 from crfloyd/feature/json-api-…
…dotnet#258 Feature/json-api-dotnet#258
- Loading branch information
Showing
14 changed files
with
234 additions
and
25 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
12 changes: 12 additions & 0 deletions
12
...esults/Benchmarks.JsonApiContext.PathIsRelationship_Benchmarks-report-github.md
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,12 @@ | ||
```ini | ||
BenchmarkDotNet=v0.10.10, OS=Mac OS X 10.12 | ||
Processor=Intel Core i5-5257U CPU 2.70GHz (Broadwell), ProcessorCount=4 | ||
.NET Core SDK=2.1.4 | ||
[Host] : .NET Core 2.0.5 (Framework 4.6.0.0), 64bit RyuJIT | ||
DefaultJob : .NET Core 2.0.5 (Framework 4.6.0.0), 64bit RyuJIT | ||
``` | ||
|
||
| Method | Mean | Error | StdDev | Gen 0 | Allocated | | ||
| ---------- | --------: | ---------: | ---------: | -----: | --------: | | ||
| UsingSplit | 421.08 ns | 19.3905 ns | 54.0529 ns | 0.4725 | 744 B | | ||
| Current | 52.23 ns | 0.8052 ns | 0.7532 ns | - | 0 B | |
16 changes: 16 additions & 0 deletions
16
...hmarks.LinkBuilder.LinkBuilder_GetNamespaceFromPath_Benchmarks-report-github.md
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,16 @@ | ||
``` ini | ||
|
||
BenchmarkDotNet=v0.10.10, OS=Mac OS X 10.12 | ||
Processor=Intel Core i5-5257U CPU 2.70GHz (Broadwell), ProcessorCount=4 | ||
.NET Core SDK=2.1.4 | ||
[Host] : .NET Core 2.0.5 (Framework 4.6.0.0), 64bit RyuJIT | ||
Job-XFMVNE : .NET Core 2.0.5 (Framework 4.6.0.0), 64bit RyuJIT | ||
|
||
LaunchCount=3 TargetCount=20 WarmupCount=10 | ||
|
||
``` | ||
| Method | Mean | Error | StdDev | Gen 0 | Allocated | | ||
|--------------------------- |-----------:|----------:|----------:|-------:|----------:| | ||
| UsingSplit | 1,197.6 ns | 11.929 ns | 25.933 ns | 0.9251 | 1456 B | | ||
| UsingSpanWithStringBuilder | 1,542.0 ns | 15.249 ns | 33.792 ns | 0.9460 | 1488 B | | ||
| UsingSpanWithNoAlloc | 272.6 ns | 2.265 ns | 5.018 ns | 0.0863 | 136 B | |
14 changes: 14 additions & 0 deletions
14
...marks.RequestMiddleware.ContainsMediaTypeParameters_Benchmarks-report-github.md
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,14 @@ | ||
``` ini | ||
|
||
BenchmarkDotNet=v0.10.10, OS=Mac OS X 10.12 | ||
Processor=Intel Core i5-5257U CPU 2.70GHz (Broadwell), ProcessorCount=4 | ||
.NET Core SDK=2.1.4 | ||
[Host] : .NET Core 2.0.5 (Framework 4.6.0.0), 64bit RyuJIT | ||
DefaultJob : .NET Core 2.0.5 (Framework 4.6.0.0), 64bit RyuJIT | ||
|
||
|
||
``` | ||
| Method | Mean | Error | StdDev | Gen 0 | Allocated | | ||
|----------- |----------:|----------:|----------:|-------:|----------:| | ||
| UsingSplit | 157.28 ns | 2.9689 ns | 5.8602 ns | 0.2134 | 336 B | | ||
| Current | 39.96 ns | 0.6489 ns | 0.6070 ns | - | 0 B | |
24 changes: 24 additions & 0 deletions
24
benchmarks/JsonApiContext/PathIsRelationship_Benchmarks.cs
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.Attributes; | ||
using BenchmarkDotNet.Attributes.Exporters; | ||
|
||
namespace Benchmarks.JsonApiContext | ||
{ | ||
[MarkdownExporter, MemoryDiagnoser] | ||
public class PathIsRelationship_Benchmarks | ||
{ | ||
private const string PATH = "https://example.com/api/v1/namespace/articles/relationships/author/"; | ||
|
||
[Benchmark] | ||
public void Current() | ||
=> JsonApiDotNetCore.Services.JsonApiContext.PathIsRelationship(PATH); | ||
|
||
[Benchmark] | ||
public void UsingSplit() => UsingSplitImpl(PATH); | ||
|
||
private bool UsingSplitImpl(string path) | ||
{ | ||
var split = path.Split('/'); | ||
return split[split.Length - 2] == "relationships"; | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
benchmarks/LinkBuilder/LinkBuilder_ GetNamespaceFromPath_Benchmarks.cs
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,38 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Attributes.Exporters; | ||
using BenchmarkDotNet.Attributes.Jobs; | ||
|
||
namespace Benchmarks.LinkBuilder | ||
{ | ||
[MarkdownExporter, SimpleJob(launchCount : 3, warmupCount : 10, targetCount : 20), MemoryDiagnoser] | ||
public class LinkBuilder_GetNamespaceFromPath_Benchmarks | ||
{ | ||
private const string PATH = "/api/some-really-long-namespace-path/resources/current/articles"; | ||
private const string ENTITY_NAME = "articles"; | ||
|
||
[Benchmark] | ||
public void UsingSplit() => GetNamespaceFromPath_BySplitting(PATH, ENTITY_NAME); | ||
|
||
[Benchmark] | ||
public void Current() => GetNameSpaceFromPath_Current(PATH, ENTITY_NAME); | ||
|
||
public static string GetNamespaceFromPath_BySplitting(string path, string entityName) | ||
{ | ||
var nSpace = string.Empty; | ||
var segments = path.Split('/'); | ||
|
||
for (var i = 1; i < segments.Length; i++) | ||
{ | ||
if (segments[i].ToLower() == entityName) | ||
break; | ||
|
||
nSpace += $"/{segments[i]}"; | ||
} | ||
|
||
return nSpace; | ||
} | ||
|
||
public static string GetNameSpaceFromPath_Current(string path, string entityName) | ||
=> JsonApiDotNetCore.Builders.LinkBuilder.GetNamespaceFromPath(path, entityName); | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
benchmarks/RequestMiddleware/ContainsMediaTypeParameters_Benchmarks.cs
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 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Attributes.Exporters; | ||
using JsonApiDotNetCore.Internal; | ||
|
||
namespace Benchmarks.RequestMiddleware | ||
{ | ||
[MarkdownExporter, MemoryDiagnoser] | ||
public class ContainsMediaTypeParameters_Benchmarks | ||
{ | ||
private const string MEDIA_TYPE = "application/vnd.api+json; version=1"; | ||
|
||
[Benchmark] | ||
public void UsingSplit() => UsingSplitImpl(MEDIA_TYPE); | ||
|
||
[Benchmark] | ||
public void Current() | ||
=> JsonApiDotNetCore.Middleware.RequestMiddleware.ContainsMediaTypeParameters(MEDIA_TYPE); | ||
|
||
private bool UsingSplitImpl(string mediaType) | ||
{ | ||
var mediaTypeArr = mediaType.Split(';'); | ||
return (mediaTypeArr[0] == Constants.ContentType && mediaTypeArr.Length == 2); | ||
} | ||
} | ||
} |
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
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