Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// executed with:
// var config = DefaultConfig.Instance
.WithArtifactsPath(artPath)
.AddDiagnoser(MemoryDiagnoser.Default)
.AddJob(Job.InProcess);
// BenchmarkRunner.Run(typeof(NullCoalesce), config);
public class NullCoalesce
{
private bool _toggle;
public Func<int> F { get; set; }
public NullCoalesce()
{
// F returns a const
//F = () => 0;
// F returns a value
//F = () =>
//{
// _toggle = !_toggle;
// return _toggle ? 1 : 0;
//};
}
[Benchmark]
public void BencharkM1()
{
var i = GetConditional();
}
private int M1()
=> F == null ? 0 : F();
[Benchmark]
public void BenchmarkM2()
{
var i = GetCoalesce();
}
private int M2()
=> F?.Invoke() ?? 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.