-
-
Notifications
You must be signed in to change notification settings - Fork 53
/
DataStructuresBenchmarks.cs
206 lines (176 loc) · 3.96 KB
/
DataStructuresBenchmarks.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
namespace Towel_Benchmarking;
[Tag(Program.Name, "Data Structures")]
[Tag(Program.OutputFile, nameof(DataStructuresBenchmarks))]
public class DataStructuresBenchmarks
{
[ParamsSource(nameof(RandomData))]
public Person[]? RandomTestData { get; set; }
public static Person[][] RandomData => Towel_Benchmarking.RandomData.DataStructures.RandomData;
// ListArray
[Benchmark]
public void ListArray_Add()
{
IList<Person> list = new ListArray<Person>();
foreach (Person person in RandomTestData!)
{
list.Add(person);
}
}
[Benchmark]
public void ListArray_AddWithCapacity()
{
IList<Person> list = new ListArray<Person>(RandomTestData!.Length);
foreach (Person person in RandomTestData)
{
list.Add(person);
}
}
// ListLinked
[Benchmark]
public void ListLinked_Add()
{
IList<Person> list = new ListLinked<Person>();
foreach (Person person in RandomTestData!)
{
list.Add(person);
}
}
// QueueArray
[Benchmark]
public void QueueArray_Enqueue()
{
IQueue<Person> queue = new QueueArray<Person>();
foreach (Person person in RandomTestData!)
{
queue.Enqueue(person);
}
}
[Benchmark]
public void QueueArray_EnqueueWithCapacity()
{
IQueue<Person> queue = new QueueArray<Person>(RandomTestData!.Length);
foreach (Person person in RandomTestData)
{
queue.Enqueue(person);
}
}
// QueueLinked
[Benchmark]
public void QueueLinked_Enqueue()
{
IQueue<Person> queue = new QueueLinked<Person>();
foreach (Person person in RandomTestData!)
{
queue.Enqueue(person);
}
}
// StackArray
[Benchmark]
public void StackArray_Push()
{
IStack<Person> stack = new StackArray<Person>();
foreach (Person person in RandomTestData!)
{
stack.Push(person);
}
}
[Benchmark]
public void StackArray_PushWithCapacity()
{
IStack<Person> stack = new StackArray<Person>(RandomTestData!.Length);
foreach (Person person in RandomTestData)
{
stack.Push(person);
}
}
// StackLinked
[Benchmark]
public void StackLinked_Push()
{
IStack<Person> stack = new StackLinked<Person>();
foreach (Person person in RandomTestData!)
{
stack.Push(person);
}
}
// AvlTreeLinked
[Benchmark]
public void AvlTreeLinked_AddRunTime()
{
IAvlTree<Person> tree = AvlTreeLinked.New<Person>(
(a, b) => Compare(a.FirstName, b.FirstName));
foreach (Person person in RandomTestData!)
{
tree.Add(person);
}
}
[Benchmark]
public void AvlTreeLinked_AddCompileTime()
{
IAvlTree<Person> tree = new AvlTreeLinked<Person, ComparePersonFirstName>();
foreach (Person person in RandomTestData!)
{
tree.Add(person);
}
}
// RedBlackTreeLinked
[Benchmark]
public void RedBlackTree_AddRunTime()
{
IRedBlackTree<Person> tree = RedBlackTreeLinked.New<Person>((a, b) => Compare(a.FirstName, b.FirstName));
foreach (Person person in RandomTestData!)
{
tree.Add(person);
}
}
[Benchmark]
public void RedBlackTree_AddCompileTime()
{
IRedBlackTree<Person> tree = new RedBlackTreeLinked<Person, ComparePersonFirstName>();
foreach (Person person in RandomTestData!)
{
tree.Add(person);
}
}
// SetHashLinked
[Benchmark]
public void SetHashLinked_AddRunTime()
{
ISet<Person> set = SetHashLinked.New<Person>(
(a, b) => a.Id == b.Id,
x => x.Id.GetHashCode());
foreach (Person person in RandomTestData!)
{
set.Add(person);
}
}
[Benchmark]
public void SetHashLinked_AddCompileTime()
{
ISet<Person> set = new SetHashLinked<Person, EquatePerson, HashPerson>();
foreach (Person person in RandomTestData!)
{
set.Add(person);
}
}
// SkipList
[Benchmark]
public void SkipList_Add()
{
SkipList<Person, ComparePersonFirstName, RandomNext> list = new((byte)Math.Max(Math.Log(RandomData.Length), 4), random: new());
foreach (Person person in RandomTestData!)
{
list.Add(person);
}
}
// BTree
[Benchmark]
public void BTreeLinked_Add()
{
BTreeLinked<Person, ComparePersonFirstName> list = new(4);
foreach (Person person in RandomTestData!)
{
list.Add(person);
}
}
}