-
-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathSchemaBenchmarkBase.cs
41 lines (33 loc) · 1016 Bytes
/
SchemaBenchmarkBase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
namespace Schema.NET.Benchmarks;
using System;
using System.Text.Json;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
[KeepBenchmarkFiles]
[MemoryDiagnoser]
[MinColumn]
[MaxColumn]
[HtmlExporter]
[CsvMeasurementsExporter]
[RPlotExporter]
[SimpleJob(RuntimeMoniker.Net70)]
[SimpleJob(RuntimeMoniker.Net60)]
[SimpleJob(RuntimeMoniker.Net472)]
public abstract class SchemaBenchmarkBase
{
public Thing Thing { get; set; } = default!;
private Type ThingType { get; set; } = default!;
private string SerializedThing { get; set; } = default!;
public abstract Thing InitialiseThing();
[GlobalSetup]
public virtual void Setup()
{
this.Thing = this.InitialiseThing();
this.ThingType = this.Thing.GetType();
this.SerializedThing = this.Thing.ToString();
}
[Benchmark]
public string Serialize() => this.Thing.ToString();
[Benchmark]
public object? Deserialize() => JsonSerializer.Deserialize(this.SerializedThing, this.ThingType);
}