Skip to content

Commit 04e01e5

Browse files
author
Martin Boje Carpentier
committed
Removed ignore warning, and throw NullReferenceException instead
1 parent ac1eace commit 04e01e5

7 files changed

Lines changed: 89 additions & 31 deletions
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
using BenchmarkDotNet.Attributes;
2-
using BenchmarkDotNet.Jobs;
2+
using System;
33

44
namespace GeoJSON.Text.Test.Benchmark.Deserialize
55
{
6-
[SimpleJob(RuntimeMoniker.Net60, baseline: true)]
7-
[SimpleJob(RuntimeMoniker.Net50)]
8-
[SimpleJob(RuntimeMoniker.NetCoreApp31)]
6+
[Config(typeof(TestConfig))]
97
[MemoryDiagnoser]
108
public class DeserializeFeatureCollectionLinestring
119
{
1210
string fileContents = "";
1311

14-
[Params(1000, 10000, 100000)]
12+
[Params(1000, 10000/*, 100000*/)]
1513
public int N;
1614

1715
[GlobalSetup]
@@ -20,13 +18,13 @@ public void Setup()
2018
fileContents = JsonEmbeddedFileReader.GetExpectedJson($"DeserializeFeatureCollectionLinestring_{N}");
2119
}
2220

23-
#pragma warning disable CS8603 // Possible null reference return.
2421
[Benchmark]
25-
public Net.Feature.FeatureCollection DeserializeNewtonsoft() => Newtonsoft.Json.JsonConvert.DeserializeObject<Net.Feature.FeatureCollection>(fileContents);
22+
public Net.Feature.FeatureCollection DeserializeNewtonsoft() => Newtonsoft.Json.JsonConvert.DeserializeObject<Net.Feature.FeatureCollection>(fileContents ?? "")
23+
?? throw new NullReferenceException("Deserialization should not return a null value.");
2624

2725

2826
[Benchmark]
29-
public Text.Feature.FeatureCollection DeserializeSystemTextJson() => System.Text.Json.JsonSerializer.Deserialize<Text.Feature.FeatureCollection>(fileContents);
30-
#pragma warning restore CS8603 // Possible null reference return.
27+
public Text.Feature.FeatureCollection DeserializeSystemTextJson() => System.Text.Json.JsonSerializer.Deserialize<Text.Feature.FeatureCollection>(fileContents)
28+
?? throw new NullReferenceException("Deserialization should not return a null value.");
3129
}
3230
}
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
using BenchmarkDotNet.Attributes;
2-
using BenchmarkDotNet.Jobs;
2+
using System;
33

44
namespace GeoJSON.Text.Test.Benchmark.Deserialize
55
{
6-
[SimpleJob(RuntimeMoniker.Net60, baseline: true)]
7-
[SimpleJob(RuntimeMoniker.Net50)]
8-
[SimpleJob(RuntimeMoniker.NetCoreApp31)]
6+
[Config(typeof(TestConfig))]
97
[MemoryDiagnoser]
108
public class DeserializeFeatureLinestring
119
{
@@ -17,13 +15,13 @@ public void Setup()
1715
fileContents = JsonEmbeddedFileReader.GetExpectedJson("DeserializeFeatureLinestring");
1816
}
1917

20-
#pragma warning disable CS8603 // Possible null reference return.
2118
[Benchmark]
22-
public Net.Feature.Feature<Net.Geometry.LineString> DeserializeNewtonsoft() => Newtonsoft.Json.JsonConvert.DeserializeObject<Net.Feature.Feature<Net.Geometry.LineString>>(fileContents);
19+
public Net.Feature.Feature<Net.Geometry.LineString> DeserializeNewtonsoft() => Newtonsoft.Json.JsonConvert.DeserializeObject<Net.Feature.Feature<Net.Geometry.LineString>>(fileContents)
20+
?? throw new NullReferenceException("Deserialization should not return a null value.");
2321

2422

2523
[Benchmark]
26-
public Text.Feature.Feature<Text.Geometry.LineString> DeserializeSystemTextJson() => System.Text.Json.JsonSerializer.Deserialize<Feature.Feature<Geometry.LineString>>(fileContents);
27-
#pragma warning restore CS8603 // Possible null reference return.
24+
public Text.Feature.Feature<Text.Geometry.LineString> DeserializeSystemTextJson() => System.Text.Json.JsonSerializer.Deserialize<Feature.Feature<Geometry.LineString>>(fileContents)
25+
?? throw new NullReferenceException("Deserialization should not return a null value.");
2826
}
2927
}

src/GeoJSON.Text.Test.Benchmark/Deserialize/JsonEmbeddedFileReader.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ public static string GetExpectedJson(string fileName)
1515

1616
var fileStreamName = $"{currentNamespace}.{fileName}.json";
1717

18-
Console.WriteLine(fileStreamName);
19-
20-
using (Stream stream = assembly.GetManifestResourceStream(fileStreamName))
18+
using (Stream stream = assembly.GetManifestResourceStream(fileStreamName)
19+
?? throw new NullReferenceException("Manifest stream should not be null. Incorrect filename specified."))
2120
using (StreamReader reader = new StreamReader(stream))
2221
{
2322
string result = reader.ReadToEnd();

src/GeoJSON.Text.Test.Benchmark/Serialize/SerializeFeatureCollectionLinestring.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
using BenchmarkDotNet.Attributes;
2-
using BenchmarkDotNet.Jobs;
32
using System.Collections.Generic;
43

54
namespace GeoJSON.Text.Test.Benchmark.Serialize
65
{
7-
[SimpleJob(RuntimeMoniker.Net60, baseline: true)]
8-
[SimpleJob(RuntimeMoniker.Net50)]
9-
[SimpleJob(RuntimeMoniker.NetCoreApp31)]
6+
[Config(typeof(TestConfig))]
107
[MemoryDiagnoser]
118
public class SerializeFeatureCollectionLinestring
129
{
@@ -16,7 +13,7 @@ public class SerializeFeatureCollectionLinestring
1613
// GeoJson.Text
1714
private Text.Feature.FeatureCollection featureCollectionGeoJsonTEXT = new Text.Feature.FeatureCollection();
1815

19-
[Params(1000, 10000, 100000)]
16+
[Params(1000, 10000)]
2017
public int N;
2118

2219
[GlobalSetup]
@@ -30,7 +27,7 @@ public void Setup()
3027
for (int i = 0; i< N; i++)
3128
{
3229
var linestringNET = new Net.Geometry.LineString(line);
33-
GeoJSON.Net.Feature.Feature featureNET = new Net.Feature.Feature(linestringNET);
30+
Net.Feature.Feature featureNET = new Net.Feature.Feature(linestringNET);
3431
featureCollectionGeoJsonNET.Features.Add(featureNET);
3532

3633
var linestringTEXT = new Text.Geometry.LineString(line);

src/GeoJSON.Text.Test.Benchmark/Serialize/SerializeFeatureLinestring.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
using BenchmarkDotNet.Attributes;
2-
using BenchmarkDotNet.Jobs;
32
using System.Collections.Generic;
43

54
namespace GeoJSON.Text.Test.Benchmark.Serialize
65
{
7-
[SimpleJob(RuntimeMoniker.Net60, baseline: true)]
8-
[SimpleJob(RuntimeMoniker.Net50)]
9-
[SimpleJob(RuntimeMoniker.NetCoreApp31)]
10-
[MemoryDiagnoser]
6+
[Config(typeof(TestConfig))]
117
public class SerializeFeatureLinestring
128
{
139
// GeoJson.NET
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using BenchmarkDotNet.Columns;
2+
using BenchmarkDotNet.Configs;
3+
using BenchmarkDotNet.Diagnosers;
4+
using BenchmarkDotNet.Environments;
5+
using BenchmarkDotNet.Exporters;
6+
using BenchmarkDotNet.Exporters.Csv;
7+
using BenchmarkDotNet.Jobs;
8+
using BenchmarkDotNet.Order;
9+
using BenchmarkDotNet.Reports;
10+
using BenchmarkDotNet.Running;
11+
using Perfolizer.Horology;
12+
using System.Collections.Generic;
13+
using System.Collections.Immutable;
14+
using System.Linq;
15+
16+
namespace GeoJSON.Text.Test.Benchmark
17+
{
18+
public class TestConfig : ManualConfig
19+
{
20+
public TestConfig()
21+
{
22+
AddJob(Job.Default.WithRuntime(CoreRuntime.Core31)
23+
.WithLaunchCount(1) // benchmark process will be launched only once
24+
.WithWarmupCount(3) // 3 warmup iteration
25+
.WithIterationCount(3), // 3 target iteration,
26+
Job.Default.WithRuntime(CoreRuntime.Core50)
27+
.WithLaunchCount(1) // benchmark process will be launched only once
28+
.WithWarmupCount(3) // 3 warmup iteration
29+
.WithIterationCount(3), // 3 target iteration,
30+
Job.Default.WithRuntime(CoreRuntime.Core60)
31+
.WithLaunchCount(1) // benchmark process will be launched only once
32+
.WithWarmupCount(3) // 3 warmup iteration
33+
.WithIterationCount(3)); // 3 target iteration);
34+
35+
AddColumn(RankColumn.Roman);
36+
AddExporter(CsvMeasurementsExporter.Default, RPlotExporter.Default);
37+
AddDiagnoser(MemoryDiagnoser.Default);
38+
39+
WithOrderer(new FastestToSlowestOrderer());
40+
}
41+
42+
private class FastestToSlowestOrderer : IOrderer
43+
{
44+
public IEnumerable<BenchmarkCase> GetExecutionOrder(ImmutableArray<BenchmarkCase> benchmarksCase) =>
45+
from benchmark in benchmarksCase
46+
orderby benchmark.Parameters["X"] descending,
47+
benchmark.Descriptor.WorkloadMethodDisplayInfo
48+
select benchmark;
49+
50+
public string GetHighlightGroupKey(BenchmarkCase benchmarkCase) => "";
51+
52+
public string GetLogicalGroupKey(ImmutableArray<BenchmarkCase> allBenchmarksCases, BenchmarkCase benchmarkCase) =>
53+
benchmarkCase.Job.DisplayInfo + "_" + benchmarkCase.Parameters.DisplayInfo;
54+
55+
public IEnumerable<IGrouping<string, BenchmarkCase>> GetLogicalGroupOrder(IEnumerable<IGrouping<string, BenchmarkCase>> logicalGroups) =>
56+
logicalGroups.OrderBy(it => it.Key);
57+
58+
public IEnumerable<BenchmarkCase> GetSummaryOrder(ImmutableArray<BenchmarkCase> benchmarksCases, Summary summary)
59+
{
60+
var benchmarkResult = from benchmark in benchmarksCases
61+
orderby summary[benchmark].ResultStatistics.Mean
62+
select benchmark;
63+
64+
return benchmarkResult;
65+
}
66+
67+
public bool SeparateLogicalGroups => true;
68+
}
69+
}
70+
}

0 commit comments

Comments
 (0)