Skip to content

Commit c7f391a

Browse files
committed
bench(serializer): test simple object serialization
1 parent edc88c5 commit c7f391a

8 files changed

+99
-4
lines changed

benchmarks/BenchmarkDotNet.Artifacts/results/Benchmarks.Serialization.JsonApiDeserializer_Benchmarks-report-github.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ Processor=Intel Core i5-5257U CPU 2.70GHz (Broadwell), ProcessorCount=4
1010
```
1111
| Method | Mean | Error | StdDev |
1212
|------------------------ |---------:|----------:|----------:|
13-
| DeserializeSimpleObject | 27.29 us | 0.5275 us | 0.5863 us |
13+
| DeserializeSimpleObject | 27.34 us | 0.5458 us | 0.7472 us |
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Method,Job,AnalyzeLaunchVariance,EvaluateOverhead,MaxAbsoluteError,MaxRelativeError,MinInvokeCount,MinIterationTime,RemoveOutliers,Affinity,Jit,Platform,Runtime,AllowVeryLargeObjects,Concurrent,CpuGroups,Force,RetainVm,Server,Arguments,BuildConfiguration,Clock,EngineFactory,EnvironmentVariables,Toolchain,InvocationCount,IterationTime,LaunchCount,RunStrategy,TargetCount,UnrollFactor,WarmupCount,Mean,Error,StdDev
2-
DeserializeSimpleObject,Default,False,Default,Default,Default,Default,Default,Default,0,RyuJit,X64,Core,False,True,False,True,False,False,Default,Default,Default,Default,Default,Default,1,Default,Default,Default,Default,16,Default,27.29 us,0.5275 us,0.5863 us
2+
DeserializeSimpleObject,Default,False,Default,Default,Default,Default,Default,Default,0,RyuJit,X64,Core,False,True,False,True,False,False,Default,Default,Default,Default,Default,Default,1,Default,Default,Default,Default,16,Default,27.34 us,0.5458 us,0.7472 us

benchmarks/BenchmarkDotNet.Artifacts/results/Benchmarks.Serialization.JsonApiDeserializer_Benchmarks-report.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<table>
2525
<thead><tr><th> Method</th><th>Mean</th><th>Error</th><th>StdDev</th>
2626
</tr>
27-
</thead><tbody><tr><td>DeserializeSimpleObject</td><td>27.29 us</td><td>0.5275 us</td><td>0.5863 us</td>
27+
</thead><tbody><tr><td>DeserializeSimpleObject</td><td>27.34 us</td><td>0.5458 us</td><td>0.7472 us</td>
2828
</tr></tbody></table>
2929
</body>
3030
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
``` ini
2+
3+
BenchmarkDotNet=v0.10.10, OS=Mac OS X 10.12
4+
Processor=Intel Core i5-5257U CPU 2.70GHz (Broadwell), ProcessorCount=4
5+
.NET Core SDK=2.0.0
6+
[Host] : .NET Core 1.1.4 (Framework 4.6.25714.03), 64bit RyuJIT
7+
DefaultJob : .NET Core 1.1.4 (Framework 4.6.25714.03), 64bit RyuJIT
8+
9+
10+
```
11+
| Method | Mean | Error | StdDev |
12+
|------------------------ |---------:|----------:|----------:|
13+
| DeserializeSimpleObject | 6.940 us | 0.1364 us | 0.1675 us |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Method,Job,AnalyzeLaunchVariance,EvaluateOverhead,MaxAbsoluteError,MaxRelativeError,MinInvokeCount,MinIterationTime,RemoveOutliers,Affinity,Jit,Platform,Runtime,AllowVeryLargeObjects,Concurrent,CpuGroups,Force,RetainVm,Server,Arguments,BuildConfiguration,Clock,EngineFactory,EnvironmentVariables,Toolchain,InvocationCount,IterationTime,LaunchCount,RunStrategy,TargetCount,UnrollFactor,WarmupCount,Mean,Error,StdDev
2+
DeserializeSimpleObject,Default,False,Default,Default,Default,Default,Default,Default,0,RyuJit,X64,Core,False,True,False,True,False,False,Default,Default,Default,Default,Default,Default,1,Default,Default,Default,Default,16,Default,6.940 us,0.1364 us,0.1675 us
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!DOCTYPE html>
2+
<html lang='en'>
3+
<head>
4+
<meta charset='utf-8' />
5+
<title>JsonApiSerializer_Benchmarks</title>
6+
7+
<style type="text/css">
8+
table { border-collapse: collapse; display: block; width: 100%; overflow: auto; }
9+
td, th { padding: 6px 13px; border: 1px solid #ddd; }
10+
tr { background-color: #fff; border-top: 1px solid #ccc; }
11+
tr:nth-child(even) { background: #f8f8f8; }
12+
</style>
13+
</head>
14+
<body>
15+
<pre><code>
16+
BenchmarkDotNet=v0.10.10, OS=Mac OS X 10.12
17+
Processor=Intel Core i5-5257U CPU 2.70GHz (Broadwell), ProcessorCount=4
18+
.NET Core SDK=2.0.0
19+
[Host] : .NET Core 1.1.4 (Framework 4.6.25714.03), 64bit RyuJIT
20+
DefaultJob : .NET Core 1.1.4 (Framework 4.6.25714.03), 64bit RyuJIT
21+
</code></pre>
22+
<pre><code></code></pre>
23+
24+
<table>
25+
<thead><tr><th> Method</th><th>Mean</th><th>Error</th><th>StdDev</th>
26+
</tr>
27+
</thead><tbody><tr><td>DeserializeSimpleObject</td><td>6.940 us</td><td>0.1364 us</td><td>0.1675 us</td>
28+
</tr></tbody></table>
29+
</body>
30+
</html>

benchmarks/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
namespace Benchmarks {
55
class Program {
66
static void Main(string[] args) {
7-
var summary = BenchmarkRunner.Run<JsonApiDeserializer_Benchmarks>();
7+
BenchmarkRunner.Run<JsonApiDeserializer_Benchmarks>();
8+
BenchmarkRunner.Run<JsonApiSerializer_Benchmarks>();
89
}
910
}
1011
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using BenchmarkDotNet.Attributes;
4+
using JsonApiDotNetCore.Builders;
5+
using JsonApiDotNetCore.Configuration;
6+
using JsonApiDotNetCore.Internal.Generics;
7+
using JsonApiDotNetCore.Models;
8+
using JsonApiDotNetCore.Serialization;
9+
using JsonApiDotNetCore.Services;
10+
using Moq;
11+
using Newtonsoft.Json;
12+
using Newtonsoft.Json.Serialization;
13+
14+
namespace Benchmarks.Serialization {
15+
public class JsonApiSerializer_Benchmarks {
16+
private const string TYPE_NAME = "simple-types";
17+
private static readonly SimpleType Content = new SimpleType();
18+
19+
private readonly JsonApiSerializer _jsonApiSerializer;
20+
21+
public JsonApiSerializer_Benchmarks() {
22+
var contextGraphBuilder = new ContextGraphBuilder();
23+
contextGraphBuilder.AddResource<SimpleType>(TYPE_NAME);
24+
var contextGraph = contextGraphBuilder.Build();
25+
26+
var jsonApiContextMock = new Mock<IJsonApiContext>();
27+
jsonApiContextMock.SetupAllProperties();
28+
jsonApiContextMock.Setup(m => m.ContextGraph).Returns(contextGraph);
29+
jsonApiContextMock.Setup(m => m.AttributesToUpdate).Returns(new Dictionary<AttrAttribute, object>());
30+
31+
var jsonApiOptions = new JsonApiOptions();
32+
jsonApiOptions.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
33+
jsonApiContextMock.Setup(m => m.Options).Returns(jsonApiOptions);
34+
35+
var genericProcessorFactoryMock = new Mock<IGenericProcessorFactory>();
36+
37+
var documentBuilder = new DocumentBuilder(jsonApiContextMock.Object);
38+
_jsonApiSerializer = new JsonApiSerializer(jsonApiContextMock.Object, documentBuilder);
39+
}
40+
41+
[Benchmark]
42+
public object DeserializeSimpleObject() => _jsonApiSerializer.Serialize(Content);
43+
44+
private class SimpleType : Identifiable {
45+
[Attr("name")]
46+
public string Name { get; set; }
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)