Skip to content

Commit 33a9145

Browse files
prozolicxtqqczze
andauthored
Add benchmark for ImmutableArrayExtensions (#4915)
Add benchmark for ImmutableArrayExtensions --------- Co-authored-by: xtqqczze <[email protected]>
1 parent 894a70f commit 33a9145

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using BenchmarkDotNet.Attributes;
6+
using MicroBenchmarks;
7+
using System.Collections.Generic;
8+
using System.Collections.Immutable;
9+
10+
namespace System.Linq.Tests
11+
{
12+
[BenchmarkCategory(Categories.Libraries, Categories.LINQ)]
13+
public class Perf_ImmutableArrayExtensions
14+
{
15+
private ImmutableArray<int> _immutableArray;
16+
17+
[GlobalSetup]
18+
public void GlobalSetup() => _immutableArray = ImmutableArray.CreateRange(Enumerable.Range(0, LinqTestData.Size));
19+
20+
public IEnumerable<object> Arguments()
21+
{
22+
yield return LinqTestData.IEnumerable;
23+
yield return LinqTestData.ICollection;
24+
yield return LinqTestData.IList;
25+
yield return LinqTestData.Array;
26+
yield return LinqTestData.List;
27+
}
28+
29+
[Benchmark]
30+
[ArgumentsSource(nameof(Arguments))]
31+
[MemoryRandomization]
32+
public bool SequenceEqual(LinqTestData input) => ImmutableArrayExtensions.SequenceEqual(_immutableArray, input.Collection);
33+
34+
}
35+
}

0 commit comments

Comments
 (0)