forked from HdrHistogram/HdrHistogram.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerialisationBenchmark.cs
More file actions
61 lines (52 loc) · 1.94 KB
/
Copy pathSerialisationBenchmark.cs
File metadata and controls
61 lines (52 loc) · 1.94 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
using BenchmarkDotNet.Attributes;
using HdrHistogram.Encoding;
namespace HdrHistogram.Benchmarking.Serialisation
{
[MemoryDiagnoser]
public class SerialisationBenchmark
{
private LongHistogram _source = null!;
private Utilities.ByteBuffer _encodeBuffer = null!;
private Utilities.ByteBuffer _decodeBuffer = null!;
private Utilities.ByteBuffer _compressedDecodeBuffer = null!;
[GlobalSetup]
public void Setup()
{
_source = new LongHistogram(3600_000_000L, 3);
for (long i = 0; i < 10_000; i++)
{
_source.RecordValue(1000L * i);
}
var capacity = _source.GetNeededByteBufferCapacity();
_encodeBuffer = Utilities.ByteBuffer.Allocate(capacity);
// Pre-encode for uncompressed decode benchmark
_source.Encode(_decodeBuffer = Utilities.ByteBuffer.Allocate(capacity), HistogramEncoderV2.Instance);
// Pre-encode for compressed decode benchmark
_source.EncodeIntoCompressedByteBuffer(_compressedDecodeBuffer = Utilities.ByteBuffer.Allocate(capacity));
}
[Benchmark]
public int Encode()
{
_encodeBuffer.Position = 0;
return _source.Encode(_encodeBuffer, HistogramEncoderV2.Instance);
}
[Benchmark]
public HistogramBase Decode()
{
_decodeBuffer.Position = 0;
return HistogramEncoding.DecodeFromByteBuffer(_decodeBuffer, 0);
}
[Benchmark]
public int EncodeCompressed()
{
_encodeBuffer.Position = 0;
return _source.EncodeIntoCompressedByteBuffer(_encodeBuffer);
}
[Benchmark]
public HistogramBase DecodeCompressed()
{
_compressedDecodeBuffer.Position = 0;
return HistogramEncoding.DecodeFromCompressedByteBuffer(_compressedDecodeBuffer, 0);
}
}
}