Skip to content

Commit e6dc607

Browse files
author
Martin Boje Carpentier
committed
Added simple serializing benchmarking. Could not make the benchmarking run with the directory.build.props file, so i removed it, since the solution can be signed as part of the deploy nuget command
1 parent 66db54e commit e6dc607

8 files changed

Lines changed: 229 additions & 8 deletions

src/Directory.Build.props

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using BenchmarkDotNet.Attributes;
2+
using BenchmarkDotNet.Jobs;
3+
using System;
4+
using System.Security.Cryptography;
5+
6+
namespace GeoJSON.Text.Test.Benchmark
7+
{
8+
[SimpleJob(RuntimeMoniker.Net60)]
9+
[SimpleJob(RuntimeMoniker.Net50)]
10+
public class BenchmarkDeserialize
11+
{
12+
private const int N = 10000;
13+
private readonly byte[] data;
14+
15+
private readonly SHA256 sha256 = SHA256.Create();
16+
private readonly MD5 md5 = MD5.Create();
17+
18+
public BenchmarkDeserialize()
19+
{
20+
data = new byte[N];
21+
new Random(42).NextBytes(data);
22+
}
23+
24+
[Benchmark]
25+
public byte[] Sha256() => sha256.ComputeHash(data);
26+
27+
[Benchmark]
28+
public byte[] Md5() => md5.ComputeHash(data);
29+
}
30+
}
31+
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using BenchmarkDotNet.Attributes;
2+
using BenchmarkDotNet.Jobs;
3+
using System;
4+
5+
using System.Collections.Generic;
6+
using System.Security.Cryptography;
7+
8+
namespace GeoJSON.Text.Test.Benchmark
9+
{
10+
[SimpleJob(RuntimeMoniker.Net60)]
11+
[SimpleJob(RuntimeMoniker.Net50)]
12+
[SimpleJob(RuntimeMoniker.NetCoreApp31)]
13+
[RPlotExporter]
14+
public class BenchmarkSerializeFeatureCollectionLinestring
15+
{
16+
// GeoJson.NET
17+
private Net.Feature.FeatureCollection featureCollectionGeoJsonNET;
18+
19+
// GeoJson.Text
20+
private Text.Feature.FeatureCollection featureCollectionGeoJsonTEXT;
21+
22+
[Params(1000, 10000, 100000)]
23+
public int N;
24+
25+
public BenchmarkSerializeFeatureCollectionLinestring()
26+
{
27+
var featuresNET = new List<Net.Feature.Feature>();
28+
var featuresTEXT = new List<Text.Feature.Feature>();
29+
30+
for (int i = 0; i< N; i++)
31+
{
32+
var lineCoordinates = new List<List<double>>
33+
{
34+
new List<double>
35+
{
36+
-0.26092529296875,
37+
51.470691106434884
38+
},
39+
};
40+
41+
var linestringNET = new Net.Geometry.LineString(lineCoordinates);
42+
var linestringTEXT = new Text.Geometry.LineString(lineCoordinates);
43+
44+
var featureNET = new Net.Feature.Feature(linestringNET);
45+
var featureTEXT = new Text.Feature.Feature(linestringTEXT);
46+
47+
featuresNET.Add(featureNET);
48+
featuresTEXT.Add(featureTEXT);
49+
}
50+
51+
featureCollectionGeoJsonNET = new Net.Feature.FeatureCollection(featuresNET);
52+
featureCollectionGeoJsonTEXT = new Text.Feature.FeatureCollection(featuresTEXT);
53+
}
54+
55+
[Benchmark]
56+
public void SerializeNewtonsoft()
57+
{
58+
Newtonsoft.Json.JsonConvert.SerializeObject(featureCollectionGeoJsonNET);
59+
}
60+
61+
[Benchmark]
62+
public void SerializeSystemTextJson()
63+
{
64+
System.Text.Json.JsonSerializer.Serialize(featureCollectionGeoJsonTEXT);
65+
}
66+
}
67+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
using BenchmarkDotNet.Attributes;
2+
using BenchmarkDotNet.Jobs;
3+
using System;
4+
5+
using System.Collections.Generic;
6+
using System.Security.Cryptography;
7+
8+
namespace GeoJSON.Text.Test.Benchmark
9+
{
10+
[SimpleJob(RuntimeMoniker.Net60)]
11+
[SimpleJob(RuntimeMoniker.Net50)]
12+
[SimpleJob(RuntimeMoniker.NetCoreApp31)]
13+
[RPlotExporter]
14+
public class BenchmarkSerializeFeatureLinestring
15+
{
16+
// GeoJson.NET
17+
private Net.Feature.Feature<Net.Geometry.LineString, Dictionary<string, string>>? featureLinestringGeoJsonNET;
18+
19+
// GeoJson.Text
20+
private Text.Feature.Feature<Text.Geometry.LineString, Dictionary<string, string>>? featureLinestringGeoJsonTEXT;
21+
22+
[GlobalSetup]
23+
public void Setup()
24+
{
25+
var lineCoordinates = new List<List<double>>
26+
{
27+
new List<double>
28+
{
29+
-0.26092529296875,
30+
51.470691106434884
31+
},
32+
new List<double>
33+
{
34+
-1.26092529296875,
35+
51.470691106434884
36+
},
37+
new List<double>
38+
{
39+
-2.26092529296875,
40+
51.470691106434884
41+
},
42+
new List<double>
43+
{
44+
-3.26092529296875,
45+
51.470691106434884
46+
},
47+
new List<double>
48+
{
49+
-4.26092529296875,
50+
51.470691106434884
51+
},
52+
new List<double>
53+
{
54+
-5.26092529296875,
55+
51.470691106434884
56+
},
57+
};
58+
59+
var linestringNET = new Net.Geometry.LineString(lineCoordinates);
60+
var linestringTEXT = new Text.Geometry.LineString(lineCoordinates);
61+
62+
Dictionary<string, string> props = new Dictionary<string, string>
63+
{
64+
{ "key1", "value1" },
65+
{ "key2", "value2" }
66+
};
67+
68+
featureLinestringGeoJsonNET = new Net.Feature.Feature<Net.Geometry.LineString, Dictionary<string, string>>(linestringNET, props, "1");
69+
featureLinestringGeoJsonTEXT = new Text.Feature.Feature<Text.Geometry.LineString, Dictionary<string, string>>(linestringTEXT, props, "1");
70+
71+
}
72+
73+
[Benchmark]
74+
public void SerializeNewtonsoft()
75+
{
76+
Newtonsoft.Json.JsonConvert.SerializeObject(featureLinestringGeoJsonNET);
77+
}
78+
79+
[Benchmark]
80+
public void SerializeSystemTextJson()
81+
{
82+
System.Text.Json.JsonSerializer.Serialize(featureLinestringGeoJsonTEXT);
83+
}
84+
}
85+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFrameworks>netcoreapp3.1;net5;net6</TargetFrameworks>
6+
<ImplicitUsings>disable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<SignAssembly>False</SignAssembly>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="BenchmarkDotNet" Version="0.13.1" />
13+
<PackageReference Include="GeoJSON.Net" Version="1.2.19" />
14+
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
15+
</ItemGroup>
16+
17+
<ItemGroup>
18+
<ProjectReference Include="..\GeoJSON.Text\GeoJSON.Text.csproj" />
19+
</ItemGroup>
20+
21+
</Project>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+

2+
using BenchmarkDotNet.Running;
3+
using GeoJSON.Text.Test.Benchmark;
4+
5+
namespace GeoJSON.Text.Test.Benchmark
6+
{
7+
public class Program
8+
{
9+
public static void Main(string[] args)
10+
{
11+
//var summary = BenchmarkRunner.Run<BenchmarkDeserialize>();
12+
//var summary2 = BenchmarkRunner.Run<BenchmarkSerializeFeatureCollectionLinestring>();
13+
var summary2 = BenchmarkRunner.Run<BenchmarkSerializeFeatureLinestring>();
14+
}
15+
}
16+
}
17+
18+
File renamed without changes.

src/GeoJSON.Text.sln

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1212
EndProject
1313
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GeoJSON.Text", "GeoJSON.Text\GeoJSON.Text.csproj", "{ECD95D99-8429-4358-92AE-1C51061D774C}"
1414
EndProject
15-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GeoJSON.Text.Tests", "GeoJSON.Text.Tests\GeoJSON.Text.Tests.csproj", "{6C93B314-9208-4684-B873-172F7EC81689}"
15+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GeoJSON.Text.Test.Unit", "GeoJSON.Text.Tests\GeoJSON.Text.Test.Unit.csproj", "{6C93B314-9208-4684-B873-172F7EC81689}"
16+
EndProject
17+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GeoJSON.Text.Test.Benchmark", "GeoJSON.Text.Test.Benchmark\GeoJSON.Text.Test.Benchmark.csproj", "{7C065EE0-D877-4D1C-AF2C-A6A6665C64DC}"
1618
EndProject
1719
Global
1820
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -28,6 +30,10 @@ Global
2830
{6C93B314-9208-4684-B873-172F7EC81689}.Debug|Any CPU.Build.0 = Debug|Any CPU
2931
{6C93B314-9208-4684-B873-172F7EC81689}.Release|Any CPU.ActiveCfg = Release|Any CPU
3032
{6C93B314-9208-4684-B873-172F7EC81689}.Release|Any CPU.Build.0 = Release|Any CPU
33+
{7C065EE0-D877-4D1C-AF2C-A6A6665C64DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
34+
{7C065EE0-D877-4D1C-AF2C-A6A6665C64DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
35+
{7C065EE0-D877-4D1C-AF2C-A6A6665C64DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
36+
{7C065EE0-D877-4D1C-AF2C-A6A6665C64DC}.Release|Any CPU.Build.0 = Release|Any CPU
3137
EndGlobalSection
3238
GlobalSection(SolutionProperties) = preSolution
3339
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)