Last active
November 21, 2020 11:05
-
-
Save zpqrtbnk/490025ea4b720ba2f06ae827c88f18ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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