Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion BitFaster.Caching.ThroughputAnalysis/ConfigFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static (ThroughputBenchmarkBase, IThroughputBenchConfig, int) Create(Mode
case Mode.Update:
return (new UpdateThroughputBenchmark(), new ZipfConfig(iterations, samples, s, n), cacheSize);
case Mode.Evict:
return (new ReadThroughputBenchmark(), new EvictionConfig(iterations, samples, maxThreads), cacheSize);
return (new ReadThroughputBenchmark() { Initialize = c => EvictionInit(c) }, new EvictionConfig(iterations, samples, maxThreads), cacheSize);
}

throw new InvalidOperationException();
Expand All @@ -50,5 +50,13 @@ public static (ThroughputBenchmarkBase, IThroughputBenchConfig, int) Create(Mode
< 5_000_000 => cacheSize * 2,
_ => cacheSize
};

private static void EvictionInit(ICache<int, int> cache)
{
Parallel.ForEach(Enumerable.Range(0, cache.Policy.Eviction.Value.Capacity).Select(i => -i), i =>
{
cache.GetOrAdd(i, key => i);
});
}
}
}
4 changes: 4 additions & 0 deletions BitFaster.Caching.ThroughputAnalysis/ThroughputBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ public interface IThroughputBenchmark

public abstract class ThroughputBenchmarkBase
{
public Action<ICache<int, int>> Initialize { get; set; }

public double Run(int warmup, int runs, int threads, IThroughputBenchConfig config, ICache<int, int> cache)
{
double[] results = new double[warmup + runs];

Initialize?.Invoke(cache);

for (int i = 0; i < warmup + runs; i++)
{
results[i] = Run(threads, config, cache);
Expand Down