-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReuseBenchmarks.cs
More file actions
79 lines (69 loc) · 2.48 KB
/
Copy pathReuseBenchmarks.cs
File metadata and controls
79 lines (69 loc) · 2.48 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
74
75
76
77
78
79
using BenchmarkDotNet.Attributes;
using System.Diagnostics;
using Store = SharedMemoryStore.MemoryStore;
namespace SharedMemoryStore.Benchmarks;
[MemoryDiagnoser]
public class ReuseBenchmarks
{
private Store _store = null!;
private long _configuredCapacityBytes;
private readonly byte[] _key = [1];
private readonly byte[] _value = [1];
[GlobalSetup]
public void Setup()
{
var options = BenchmarkStoreFactory.Options(slotCount: 1);
_configuredCapacityBytes = options.TotalBytes;
_store = BenchmarkStoreFactory.Create(options);
}
[GlobalCleanup]
public void Cleanup() => _store.Dispose();
[Benchmark]
public ReuseValidationResult PublishRemoveReuseCycle()
{
StoreStatus status = StoreStatus.Success;
var process = Process.GetCurrentProcess();
process.Refresh();
var initialCommittedBytes = process.PrivateMemorySize64;
for (var i = 0; i < BenchmarkEnvironment.ReuseCycleCount; i++)
{
_value[0] = (byte)i;
status = _store.TryPublish(_key, _value);
if (status != StoreStatus.Success)
{
break;
}
status = _store.TryRemove(_key);
if (status != StoreStatus.Success)
{
break;
}
}
process.Refresh();
var finalCommittedBytes = process.PrivateMemorySize64;
var committedGrowthBytes = Math.Max(0, finalCommittedBytes - initialCommittedBytes);
var allowedGrowthBytes = (long)Math.Ceiling(_configuredCapacityBytes * BenchmarkEnvironment.CommittedMemoryToleranceRatio)
+ BenchmarkEnvironment.DocumentedFixedOverheadBytes;
var diagnostics = _store.GetDiagnostics();
return new ReuseValidationResult(
BenchmarkEnvironment.ReuseCycleCount,
_configuredCapacityBytes,
initialCommittedBytes,
finalCommittedBytes,
committedGrowthBytes,
allowedGrowthBytes,
status,
diagnostics.FreeSlotCount,
status == StoreStatus.Success && diagnostics.FreeSlotCount == 1 && committedGrowthBytes <= allowedGrowthBytes);
}
}
public readonly record struct ReuseValidationResult(
int CycleCount,
long ConfiguredCapacityBytes,
long InitialCommittedBytes,
long FinalCommittedBytes,
long CommittedGrowthBytes,
long AllowedGrowthBytes,
StoreStatus FinalStatus,
int FreeSlotCount,
bool Passed);