Skip to content

Commit 18dcd88

Browse files
authored
warmup (#277)
1 parent 167d937 commit 18dcd88

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

BitFaster.Caching.ThroughputAnalysis/ConfigFactory.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static (ThroughputBenchmarkBase, IThroughputBenchConfig, int) Create(Mode
2727
case Mode.Update:
2828
return (new UpdateThroughputBenchmark(), new ZipfConfig(iterations, samples, s, n), cacheSize);
2929
case Mode.Evict:
30-
return (new ReadThroughputBenchmark(), new EvictionConfig(iterations, samples, maxThreads), cacheSize);
30+
return (new ReadThroughputBenchmark() { Initialize = c => EvictionInit(c) }, new EvictionConfig(iterations, samples, maxThreads), cacheSize);
3131
}
3232

3333
throw new InvalidOperationException();
@@ -50,5 +50,13 @@ public static (ThroughputBenchmarkBase, IThroughputBenchConfig, int) Create(Mode
5050
< 5_000_000 => cacheSize * 2,
5151
_ => cacheSize
5252
};
53+
54+
private static void EvictionInit(ICache<int, int> cache)
55+
{
56+
Parallel.ForEach(Enumerable.Range(0, cache.Policy.Eviction.Value.Capacity).Select(i => -i), i =>
57+
{
58+
cache.GetOrAdd(i, key => i);
59+
});
60+
}
5361
}
5462
}

BitFaster.Caching.ThroughputAnalysis/ThroughputBenchmark.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ public interface IThroughputBenchmark
1313

1414
public abstract class ThroughputBenchmarkBase
1515
{
16+
public Action<ICache<int, int>> Initialize { get; set; }
17+
1618
public double Run(int warmup, int runs, int threads, IThroughputBenchConfig config, ICache<int, int> cache)
1719
{
1820
double[] results = new double[warmup + runs];
1921

22+
Initialize?.Invoke(cache);
23+
2024
for (int i = 0; i < warmup + runs; i++)
2125
{
2226
results[i] = Run(threads, config, cache);

0 commit comments

Comments
 (0)