Created
February 13, 2024 12:52
-
-
Save davepcallan/aa39e0aed39df60ff6386c2720f85d5b to your computer and use it in GitHub Desktop.
Creating list with regular v collection expression approach in .NET 8
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; | |
using BenchmarkDotNet.Columns; | |
using BenchmarkDotNet.Configs; | |
using BenchmarkDotNet.Environments; | |
using BenchmarkDotNet.Jobs; | |
using BenchmarkDotNet.Reports; | |
[Config(typeof(Config))] | |
[HideColumns(Column.Job, Column.RatioSD, Column.AllocRatio)] | |
[MemoryDiagnoser] | |
[ReturnValueValidator(failOnError: true)] | |
public class CollectionExpressions | |
{ | |
[Benchmark(Baseline = true)] | |
public List<string> RegularList() | |
{ | |
return new List<string> { "apple", "banana", "orange" }; | |
} | |
[Benchmark] | |
public List<string> ColExpressionList() | |
{ | |
return ["apple", "banana", "orange"]; | |
} | |
private class Config : ManualConfig | |
{ | |
public Config() | |
{ | |
AddJob(Job.Default.WithId(".NET 8").WithRuntime(CoreRuntime.Core80)); | |
SummaryStyle = | |
SummaryStyle.Default.WithRatioStyle(RatioStyle.Trend); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment