Skip to content

Instantly share code, notes, and snippets.

@JasonBock
Created May 25, 2021 15:38
Show Gist options
  • Save JasonBock/9fe05da11591f00e8b76cf6033fdb466 to your computer and use it in GitHub Desktop.
Save JasonBock/9fe05da11591f00e8b76cf6033fdb466 to your computer and use it in GitHub Desktop.
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