|
5 | 5 | using System.Linq;
|
6 | 6 | using System.Collections.Generic;
|
7 | 7 | using BenchmarkDotNet.Attributes;
|
| 8 | +using BenchmarkDotNet.Extensions; |
8 | 9 | using MicroBenchmarks;
|
9 | 10 |
|
10 | 11 | namespace System.Collections.Tests
|
11 | 12 | {
|
12 | 13 | [BenchmarkCategory(Categories.Libraries, Categories.Collections, Categories.GenericCollections)]
|
13 |
| - public abstract class Perf_PriorityQueue<TElement, TPriority> |
| 14 | + [GenericTypeArguments(typeof(int), typeof(int))] |
| 15 | + [GenericTypeArguments(typeof(string), typeof(string))] |
| 16 | + public class Perf_PriorityQueue<TElement, TPriority> |
14 | 17 | {
|
15 |
| - [Params(10, 100, 1000, 10_000, 100_000)] |
| 18 | + [Params(10, 100, 1000)] |
16 | 19 | public int Size;
|
17 | 20 |
|
18 | 21 | private (TElement Element, TPriority Priority)[] _items;
|
19 | 22 | private PriorityQueue<TElement, TPriority> _priorityQueue;
|
20 | 23 | private PriorityQueue<TElement, TPriority> _prePopulatedPriorityQueue;
|
21 | 24 |
|
22 |
| - public abstract IEnumerable<(TElement Element, TPriority Priority)> GenerateItems(int count); |
23 |
| - |
24 | 25 | [GlobalSetup]
|
25 | 26 | public void Setup()
|
26 | 27 | {
|
27 |
| - _items = GenerateItems(Size).ToArray(); |
| 28 | + _items = ValuesGenerator.Array<TElement>(Size).Zip(ValuesGenerator.Array<TPriority>(Size)).ToArray(); |
28 | 29 | _priorityQueue = new PriorityQueue<TElement, TPriority>(initialCapacity: Size);
|
29 | 30 | _prePopulatedPriorityQueue = new PriorityQueue<TElement, TPriority>(_items);
|
30 | 31 | }
|
@@ -104,39 +105,4 @@ public void K_Max_Elements()
|
104 | 105 | }
|
105 | 106 | }
|
106 | 107 | }
|
107 |
| - |
108 |
| - public class Perf_PriorityQueue_String_String : Perf_PriorityQueue<string, string> |
109 |
| - { |
110 |
| - public override IEnumerable<(string Element, string Priority)> GenerateItems(int count) |
111 |
| - { |
112 |
| - var random = new Random(42); |
113 |
| - const int MaxSize = 30; |
114 |
| - byte[] buffer = new byte[MaxSize]; |
115 |
| - |
116 |
| - for (int i = 0; i < count; i++) |
117 |
| - { |
118 |
| - yield return (GenerateString(), GenerateString()); |
119 |
| - } |
120 |
| - |
121 |
| - string GenerateString() |
122 |
| - { |
123 |
| - int size = random.Next(MaxSize); |
124 |
| - Span<byte> slice = buffer.AsSpan().Slice(size); |
125 |
| - random.NextBytes(slice); |
126 |
| - return Convert.ToBase64String(slice); |
127 |
| - } |
128 |
| - } |
129 |
| - } |
130 |
| - |
131 |
| - public class Perf_PriorityQueue_Int_Int : Perf_PriorityQueue<int, int> |
132 |
| - { |
133 |
| - public override IEnumerable<(int Element, int Priority)> GenerateItems(int count) |
134 |
| - { |
135 |
| - var random = new Random(42); |
136 |
| - for (int i = 0; i < count; i++) |
137 |
| - { |
138 |
| - yield return (random.Next(), random.Next()); |
139 |
| - } |
140 |
| - } |
141 |
| - } |
142 | 108 | }
|
0 commit comments