forked from microsoft/graphrag
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathMemoryPipelineCacheBenchmarks.cs
More file actions
99 lines (84 loc) · 2.23 KB
/
MemoryPipelineCacheBenchmarks.cs
File metadata and controls
99 lines (84 loc) · 2.23 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using BenchmarkDotNet.Attributes;
using GraphRag.Cache;
using Microsoft.Extensions.Caching.Memory;
namespace ManagedCode.GraphRag.Benchmarks.Cache;
[MemoryDiagnoser]
public class MemoryPipelineCacheBenchmarks
{
private IMemoryCache _memoryCache = null!;
private MemoryPipelineCache _cache = null!;
private string[] _keys = null!;
private object[] _values = null!;
[Params(1_000, 10_000, 100_000)]
public int EntryCount { get; set; }
[GlobalSetup]
public void Setup()
{
_memoryCache = new MemoryCache(new MemoryCacheOptions());
_cache = new MemoryPipelineCache(_memoryCache);
_keys = new string[EntryCount];
_values = new object[EntryCount];
for (var i = 0; i < EntryCount; i++)
{
_keys[i] = $"key-{i:D8}";
_values[i] = new { Id = i, Name = $"Value-{i}", Data = new byte[100] };
}
}
[GlobalCleanup]
public void Cleanup()
{
_memoryCache.Dispose();
}
[Benchmark]
public async Task SetEntries()
{
for (var i = 0; i < EntryCount; i++)
{
await _cache.SetAsync(_keys[i], _values[i]);
}
}
[Benchmark]
public async Task GetEntries()
{
// Pre-populate
for (var i = 0; i < EntryCount; i++)
{
await _cache.SetAsync(_keys[i], _values[i]);
}
// Measure gets
for (var i = 0; i < EntryCount; i++)
{
_ = await _cache.GetAsync(_keys[i]);
}
}
[Benchmark]
public async Task HasEntries()
{
// Pre-populate
for (var i = 0; i < EntryCount; i++)
{
await _cache.SetAsync(_keys[i], _values[i]);
}
// Measure has checks
for (var i = 0; i < EntryCount; i++)
{
_ = await _cache.HasAsync(_keys[i]);
}
}
[Benchmark]
public async Task ClearCache()
{
// Pre-populate
for (var i = 0; i < EntryCount; i++)
{
await _cache.SetAsync(_keys[i], _values[i]);
}
// Measure clear
await _cache.ClearAsync();
}
[Benchmark]
public IPipelineCache CreateChildScope()
{
return _cache.CreateChild("child-scope");
}
}