Skip to content

Commit 864fcb7

Browse files
author
Martin Boje Carpentier
committed
Updated readme with benchmark
1 parent b7a06c0 commit 864fcb7

6 files changed

Lines changed: 155 additions & 2 deletions

File tree

README.md

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,86 @@ See the [Tests](https://github.com/GeoJSON-Net/GeoJSON.Text/tree/master/src/GeoJ
3232

3333
GeoJSON.Text is made to support System.Text.Json, and does not support serializing or deserializing GeoJSON models using Newtonsoft.Json.
3434

35-
If using Newtonsoft.Json support is needed, please use [GeoJSON.Net](https://github.com/GeoJSON-Net/GeoJSON.Net).
35+
If Newtonsoft.Json support is needed, please use [GeoJSON.Net](https://github.com/GeoJSON-Net/GeoJSON.Net).
36+
37+
## GeoJSON.Text vs. GeoJSON.NET
38+
39+
This project uses the System.Text.Json serializers, which has become the default and recommended serializers in .NET Core 3.1+.
40+
41+
Benchmarks shows that serializing and deserializing using System.Text.Json is approximately 100% quicker then Newtonsoft.Json and result in 75% less memory allocation when deserializing and 50% less memory allocation when serializing.
42+
43+
<details>
44+
<summary>Benchmarks</summary>
45+
46+
### Serializing comparison
47+
48+
``` ini
49+
50+
BenchmarkDotNet=v0.13.1, OS=Windows 10.0.19042.1415 (20H2/October2020Update)
51+
Intel Core i7-9850H CPU 2.60GHz, 1 CPU, 12 logical and 6 physical cores
52+
.NET SDK=6.0.100
53+
[Host] : .NET 6.0.0 (6.0.21.52210), X64 RyuJIT
54+
Job-WNYOAA : .NET 6.0.0 (6.0.21.52210), X64 RyuJIT
55+
Job-AAKTUU : .NET 5.0.13 (5.0.1321.56516), X64 RyuJIT
56+
Job-AEYDDU : .NET Core 3.1.22 (CoreCLR 4.700.21.56803, CoreFX 4.700.21.57101), X64 RyuJIT
57+
58+
IterationCount=15 LaunchCount=2 WarmupCount=10
59+
60+
```
61+
| Method | Job | Runtime | Toolchain | N | Mean | Error | StdDev | Ratio | RatioSD | Rank | Gen 0 | Gen 1 | Gen 2 | Allocated |
62+
|------------------------ |----------- |-------------- |------------- |------- |---------:|---------:|---------:|------:|--------:|-----:|-----------:|----------:|---------:|----------:|
63+
| SerializeSystemTextJson | Job-WNYOAA | .NET 6.0 | net60 | 100000 | 167.3 ms | 7.28 ms | 10.44 ms | 1.00 | 0.00 | I | 2000.0000 | - | - | 35 MB |
64+
| | | | | | | | | | | | | | | |
65+
| SerializeSystemTextJson | Job-AAKTUU | .NET 5.0 | net50 | 100000 | 188.0 ms | 5.44 ms | 7.80 ms | ? | ? | I | 2000.0000 | - | - | 65 MB |
66+
| | | | | | | | | | | | | | | |
67+
| SerializeSystemTextJson | Job-AEYDDU | .NET Core 3.1 | netcoreapp31 | 100000 | 235.6 ms | 7.85 ms | 11.26 ms | ? | ? | I | 2333.3333 | 333.3333 | 333.3333 | 65 MB |
68+
| | | | | | | | | | | | | | | |
69+
| SerializeNewtonsoft | Job-WNYOAA | .NET 6.0 | net60 | 100000 | 352.3 ms | 17.33 ms | 24.86 ms | 2.11 | 0.16 | II | 14000.0000 | 3000.0000 | - | 112 MB |
70+
| | | | | | | | | | | | | | | |
71+
| SerializeNewtonsoft | Job-AAKTUU | .NET 5.0 | net50 | 100000 | 376.6 ms | 12.81 ms | 19.17 ms | ? | ? | II | 14000.0000 | 3000.0000 | - | 112 MB |
72+
| | | | | | | | | | | | | | | |
73+
| SerializeNewtonsoft | Job-AEYDDU | .NET Core 3.1 | netcoreapp31 | 100000 | 429.6 ms | 7.57 ms | 10.61 ms | ? | ? | II | 14000.0000 | 3000.0000 | - | 112 MB |
74+
75+
76+
<p align="center">
77+
<img src="benchmarkresult/SerializeFeatureCollectionLinestring-barplot.png" width="750" title="Serializing comparison">
78+
</p>
79+
80+
### Deserializing comparison
81+
82+
``` ini
83+
84+
BenchmarkDotNet=v0.13.1, OS=Windows 10.0.19042.1415 (20H2/October2020Update)
85+
Intel Core i7-9850H CPU 2.60GHz, 1 CPU, 12 logical and 6 physical cores
86+
.NET SDK=6.0.100
87+
[Host] : .NET 6.0.0 (6.0.21.52210), X64 RyuJIT
88+
Job-WNYOAA : .NET 6.0.0 (6.0.21.52210), X64 RyuJIT
89+
Job-AAKTUU : .NET 5.0.13 (5.0.1321.56516), X64 RyuJIT
90+
Job-AEYDDU : .NET Core 3.1.22 (CoreCLR 4.700.21.56803, CoreFX 4.700.21.57101), X64 RyuJIT
91+
92+
IterationCount=15 LaunchCount=2 WarmupCount=10
93+
94+
```
95+
| Method | Job | Runtime | Toolchain | N | Mean | Error | StdDev | Ratio | RatioSD | Rank | Gen 0 | Gen 1 | Gen 2 | Allocated |
96+
|-------------------------- |----------- |-------------- |------------- |------- |-----------:|---------:|---------:|------:|--------:|-----:|------------:|-----------:|----------:|----------:|
97+
| DeserializeSystemTextJson | Job-WNYOAA | .NET 6.0 | net60 | 100000 | 719.6 ms | 38.29 ms | 57.31 ms | 1.00 | 0.00 | I | 32000.0000 | 12000.0000 | 1000.0000 | 201 MB |
98+
| | | | | | | | | | | | | | | |
99+
| DeserializeSystemTextJson | Job-AAKTUU | .NET 5.0 | net50 | 100000 | 787.3 ms | 22.38 ms | 32.80 ms | ? | ? | I | 32000.0000 | 12000.0000 | 1000.0000 | 201 MB |
100+
| | | | | | | | | | | | | | | |
101+
| DeserializeSystemTextJson | Job-AEYDDU | .NET Core 3.1 | netcoreapp31 | 100000 | 894.6 ms | 25.84 ms | 37.87 ms | ? | ? | I | 32000.0000 | 12000.0000 | 1000.0000 | 200 MB |
102+
| | | | | | | | | | | | | | | |
103+
| DeserializeNewtonsoft | Job-WNYOAA | .NET 6.0 | net60 | 100000 | 1,410.8 ms | 27.59 ms | 40.44 ms | 1.96 | 0.13 | II | 146000.0000 | 37000.0000 | 1000.0000 | 870 MB |
104+
| | | | | | | | | | | | | | | |
105+
| DeserializeNewtonsoft | Job-AAKTUU | .NET 5.0 | net50 | 100000 | 1,430.7 ms | 31.66 ms | 46.40 ms | ? | ? | II | 146000.0000 | 37000.0000 | 1000.0000 | 870 MB |
106+
| | | | | | | | | | | | | | | |
107+
| DeserializeNewtonsoft | Job-AEYDDU | .NET Core 3.1 | netcoreapp31 | 100000 | 1,656.4 ms | 40.05 ms | 58.71 ms | ? | ? | II | 145000.0000 | 37000.0000 | 1000.0000 | 869 MB |
108+
109+
110+
<p align="center">
111+
<img src="benchmarkresult/DeserializeFeatureCollectionLinestring-barplot.png" width="750" title="Deserializing comparison">
112+
</p>
113+
</details>
114+
36115

37116
## Contributing
38117
Highly welcome! Just fork away and send a pull request. We try and review most pull requests within a couple of days.
64.3 KB
Loading
65 KB
Loading
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using BenchmarkDotNet.Attributes;
2+
using System;
3+
4+
namespace GeoJSON.Text.Test.Benchmark.Deserialize
5+
{
6+
[Config(typeof(TestConfig))]
7+
public class DeserializeFeatureCollectionLinestring
8+
{
9+
string fileContents = "";
10+
11+
[Params(100000)]
12+
public int N;
13+
14+
[GlobalSetup]
15+
public void Setup()
16+
{
17+
fileContents = JsonEmbeddedFileReader.GetExpectedJson($"FeatureCollectionLinestring_{N}");
18+
}
19+
20+
[Benchmark]
21+
public Net.Feature.FeatureCollection DeserializeNewtonsoft() => Newtonsoft.Json.JsonConvert.DeserializeObject<Net.Feature.FeatureCollection>(fileContents ?? "")
22+
?? throw new NullReferenceException("Deserialization should not return a null value.");
23+
24+
25+
[Benchmark]
26+
public Text.Feature.FeatureCollection DeserializeSystemTextJson() => System.Text.Json.JsonSerializer.Deserialize<Text.Feature.FeatureCollection>(fileContents)
27+
?? throw new NullReferenceException("Deserialization should not return a null value.");
28+
}
29+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using BenchmarkDotNet.Attributes;
2+
using System.Collections.Generic;
3+
4+
namespace GeoJSON.Text.Test.Benchmark.Serialize
5+
{
6+
[Config(typeof(TestConfig))]
7+
[MemoryDiagnoser]
8+
public class SerializeFeatureCollectionLinestring
9+
{
10+
// GeoJson.NET
11+
private Net.Feature.FeatureCollection featureCollectionGeoJsonNET = new Net.Feature.FeatureCollection();
12+
13+
// GeoJson.Text
14+
private Text.Feature.FeatureCollection featureCollectionGeoJsonTEXT = new Text.Feature.FeatureCollection();
15+
16+
[Params(100000)]
17+
public int N;
18+
19+
[GlobalSetup]
20+
public void Setup()
21+
{
22+
var coordinates1 = new double[] { 10, 50 };
23+
var coordinates2 = new double[] { 10, 50 };
24+
var coordinates3 = new double[] { 10, 50 };
25+
var coordinates4 = new double[] { 10, 50 };
26+
var line = new List<IEnumerable<double>> { coordinates1, coordinates2, coordinates3, coordinates4 };
27+
for (int i = 0; i< N; i++)
28+
{
29+
var linestringNET = new Net.Geometry.LineString(line);
30+
Net.Feature.Feature featureNET = new Net.Feature.Feature(linestringNET);
31+
featureCollectionGeoJsonNET.Features.Add(featureNET);
32+
33+
var linestringTEXT = new Text.Geometry.LineString(line);
34+
Text.Feature.Feature featureTEXT = new Text.Feature.Feature(linestringTEXT);
35+
featureCollectionGeoJsonTEXT.Features.Add(featureTEXT);
36+
}
37+
}
38+
39+
[Benchmark]
40+
public string SerializeNewtonsoft() => Newtonsoft.Json.JsonConvert.SerializeObject(featureCollectionGeoJsonNET);
41+
42+
[Benchmark]
43+
public string SerializeSystemTextJson() => System.Text.Json.JsonSerializer.Serialize(featureCollectionGeoJsonTEXT);
44+
}
45+
}

src/GeoJSON.Text/GeoJSON.Text.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netcoreapp3.1;net5;net6</TargetFrameworks>
4+
<TargetFrameworks>netstandard2.0;net5;net6</TargetFrameworks>
55
<LangVersion>Latest</LangVersion>
66
<Description>.Net types for the GeoJSON RFC to be used with System.Text.Json</Description>
77
<Authors>Matt Hunt</Authors>

0 commit comments

Comments
 (0)