-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathBinaryBenchmark.ProtobufNet.cs
More file actions
26 lines (23 loc) · 861 Bytes
/
BinaryBenchmark.ProtobufNet.cs
File metadata and controls
26 lines (23 loc) · 861 Bytes
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
using BenchmarkDotNet.Attributes;
using ProtoBuf;
using SerializationBenchmarks.Models;
public partial class BinaryBenchmark
{
[Benchmark, BenchmarkCategory("Serialization", "Binary"), ArgumentsSource(nameof(GenerateDataSets))]
public byte[] ProtoBufNet_Serialize(DataSet data)
{
return DataConvert_ProtoBufNet(data.Payload);
}
[Benchmark, BenchmarkCategory("Deserialization", "Binary"), ArgumentsSource(nameof(GenerateDataSets))]
public List<User> ProtoBufNet_Deserialize(DataSet data)
{
using var ms = new MemoryStream(data.SerializedData.ProtoBufNet);
return Serializer.Deserialize<List<User>>(ms);
}
private byte[] DataConvert_ProtoBufNet(List<User> users)
{
using var ms = new MemoryStream();
Serializer.Serialize(ms, users);
return ms.ToArray();
}
}