Created
May 25, 2021 15:38
-
-
Save JasonBock/9fe05da11591f00e8b76cf6033fdb466 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
using BenchmarkDotNet.Attributes; | |
namespace ConsoleApp3 | |
{ | |
[MemoryDiagnoser] | |
public class FormatQueuedTaskMessage | |
{ | |
[Benchmark] | |
[Arguments(3)] | |
[Arguments(4)] | |
public string UseSwitch(int delayLoop) => | |
delayLoop switch | |
{ | |
3 => "Queued Background Task {Guid} is complete.", | |
_ => "Queued Background Task {Guid} was cancelled." | |
}; | |
[Benchmark] | |
[Arguments(3)] | |
[Arguments(4)] | |
public string UseTernary(int delayLoop) => | |
delayLoop == 3 ? "Queued Background Task {Guid} is complete." : | |
"Queued Background Task {Guid} was cancelled."; | |
[Benchmark] | |
[Arguments(3)] | |
[Arguments(4)] | |
public string UseTernaryInInterpolatedString(int delayLoop) => | |
$"Queued Background Task {{Guid}} {(delayLoop == 3 ? "is complete" : "was cancelled")}."; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment