-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoveReuseAllocationBenchmarks.cs
More file actions
39 lines (32 loc) · 1.03 KB
/
Copy pathRemoveReuseAllocationBenchmarks.cs
File metadata and controls
39 lines (32 loc) · 1.03 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
using BenchmarkDotNet.Attributes;
using Store = SharedMemoryStore.MemoryStore;
namespace SharedMemoryStore.Benchmarks;
[MemoryDiagnoser]
public class RemoveReuseAllocationBenchmarks
{
private Store _store = null!;
private readonly byte[] _key = [1];
private readonly byte[] _first = [1, 2, 3];
private readonly byte[] _second = [4, 5, 6];
[GlobalSetup]
public void Setup() => _store = BenchmarkStoreFactory.Create(slotCount: 1);
[GlobalCleanup]
public void Cleanup() => _store.Dispose();
[Benchmark]
public StoreStatus RemoveAndReuse()
{
var publish = _store.TryPublish(_key, _first);
if (publish != StoreStatus.Success)
{
return publish;
}
var remove = _store.TryRemove(_key);
if (remove != StoreStatus.Success)
{
return remove;
}
var republish = _store.TryPublish(_key, _second);
var cleanup = _store.TryRemove(_key);
return republish == StoreStatus.Success ? cleanup : republish;
}
}