-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathBinaryBenchmark.cs
More file actions
73 lines (67 loc) · 2.46 KB
/
BinaryBenchmark.cs
File metadata and controls
73 lines (67 loc) · 2.46 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System.Text.Json;
using System.Text.Json.Serialization;
using BenchmarkDotNet.Attributes;
using SerializationBenchmarks.Models;
using SolTechnology.Avro;
public partial class BinaryBenchmark : SerializerBenchmark
{
public IEnumerable<DataSet> GenerateDataSets()
{
var options = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase };
options.Converters.Add(new JsonStringEnumConverter());
var sets = new[]
{
#if DATASET_SMALL
new { File = "Data_Small.json", Subset = "Small" },
#endif
#if DATASET_MEDIUM
new { File = "Data_Medium.json", Subset = "Medium" },
#endif
#if DATASET_LARGE
new { File = "Data_Large.json", Subset = "Large" },
#endif
};
foreach (var set in sets)
{
var json = File.ReadAllText(set.File);
var users = JsonSerializer.Deserialize<List<User>>(json, options);
var cborData = DataConvert_CBOR(users).GetAwaiter().GetResult();
yield return new DataSet
{
Name = set.Subset,
Payload = users,
SerializedData = new()
{
AvroConvert = DataConvert_AvroConvert(users),
BSON = DataConvert_BSON(users),
CBOR = cborData,
GroBuf = DataConvert_GroBuf(users),
Hyperion = DataConvert_Hyperion(users),
MessagePack = DataConvert_MessagePack(users),
MemoryPack = DataConvert_MemoryPack(users),
MsgPack = DataConvert_MsgPack(users),
ProtoBufNet = DataConvert_ProtoBufNet(users),
}
};
}
}
public class DataSet
{
public string Name { get; set; }
public List<User> Payload { get; set; }
public SerializedData SerializedData { get; set; }
public override string ToString() => Name;
}
public class SerializedData
{
public byte[] AvroConvert { get; set; }
public byte[] BSON { get; set; }
public byte[] CBOR { get; set; }
public byte[] GroBuf { get; set; }
public byte[] Hyperion { get; set; }
public byte[] MessagePack { get; set; }
public byte[] MsgPack { get; set; }
public byte[] ProtoBufNet { get; set; }
public byte[] MemoryPack { get; set; }
}
}