Skip to content

Instantly share code, notes, and snippets.

@davepcallan
Created February 13, 2024 12:52
Show Gist options
  • Save davepcallan/aa39e0aed39df60ff6386c2720f85d5b to your computer and use it in GitHub Desktop.
Save davepcallan/aa39e0aed39df60ff6386c2720f85d5b to your computer and use it in GitHub Desktop.
Creating list with regular v collection expression approach in .NET 8
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