using System.Collections.Generic;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Toolchains.InProcess.Emit;
using Perfolizer.Horology;
using BenchmarkDotNet.Loggers;
[assembly: System.Diagnostics.Debuggable(isJITTrackingEnabled: false, isJITOptimizerDisabled: false)]
BenchmarkRunner.Run<ComparisonBenchmarkTests>(DefaultConfig.Instance.AddJob(Job.Default.WithToolchain(new InProcessEmitToolchain(timeout: TimeSpan.FromSeconds(9), logOutput: false)).WithLaunchCount(1).WithWarmupCount(5).WithIterationCount(20).WithIterationTime(TimeInterval.FromMilliseconds(80))).AddLogger(new ConsoleLogger(unicodeSupport: true, ConsoleLogger.CreateGrayScheme())).WithOptions(ConfigOptions.DisableLogFile));
public class ComparisonBenchmarkTests
internal class DataOverLatencyWithBackfillingStrategyLambda
private readonly TimeSpan _entryTtl;
public DataOverLatencyWithBackfillingStrategyLambda(TimeSpan entryTtl)
public int SetAsync(string key)
return InternalSetAsync((bytes) => DoSomething(key, bytes, _entryTtl));
private int InternalSetAsync(Func<byte[], int> internalSet)
var bytesToBackfill = new byte[0];
return internalSet(bytesToBackfill);
private int DoSomething(string key, byte[] bytes, TimeSpan entryTtl)
internal class DataOverLatencyWithBackfillingStrategy
private readonly TimeSpan _entryTtl;
public DataOverLatencyWithBackfillingStrategy(TimeSpan entryTtl)
public int SetAsync(string key)
var bytesToBackfill = new byte[0];
return DoSomething(key, bytesToBackfill, _entryTtl);
private int DoSomething(string key, byte[] bytes, TimeSpan entryTtl)
internal DataOverLatencyWithBackfillingStrategyLambda WithLambda = new DataOverLatencyWithBackfillingStrategyLambda(TimeSpan.FromSeconds(10));
internal DataOverLatencyWithBackfillingStrategy WithoutLambda = new DataOverLatencyWithBackfillingStrategy(TimeSpan.FromSeconds(10));
public void BenchWithLambda()
WithLambda.SetAsync("toto");
public void BenchWithoutLambda()
WithoutLambda.SetAsync("toto");