Files
Umbraco-CMS/tests/Umbraco.Tests.Benchmarks/EnumeratorBenchmarks.cs

34 lines
632 B
C#
Raw Normal View History

using System.Collections.Generic;
2018-12-05 12:57:23 +01:00
using BenchmarkDotNet.Attributes;
namespace Umbraco.Tests.Benchmarks;
[MemoryDiagnoser]
public class EnumeratorBenchmarks
2018-12-05 12:57:23 +01:00
{
[Benchmark(Baseline = true)]
public void WithArray()
2018-12-05 12:57:23 +01:00
{
foreach (var t in EnumerateOneWithArray(1))
2018-12-05 12:57:23 +01:00
{
;
2018-12-05 12:57:23 +01:00
}
}
2018-12-05 12:57:23 +01:00
[Benchmark]
public void WithYield()
{
foreach (var t in EnumerateOneWithYield(1))
2018-12-05 12:57:23 +01:00
{
;
2018-12-05 12:57:23 +01:00
}
}
2018-12-05 12:57:23 +01:00
private IEnumerable<T> EnumerateOneWithArray<T>(T o) => new[] { o };
2018-12-05 12:57:23 +01:00
private IEnumerable<T> EnumerateOneWithYield<T>(T o)
{
yield return o;
2018-12-05 12:57:23 +01:00
}
}