changed PriorityQueueBenchmarks

This commit is contained in:
ikpil 2024-08-04 18:35:25 +09:00
parent 153b523ea7
commit cd7c668caf
1 changed files with 35 additions and 3 deletions

View File

@ -192,7 +192,17 @@ public class PriorityQueueBenchmarks
public void EnqueueDequeue_RcSortedQueue() public void EnqueueDequeue_RcSortedQueue()
{ {
_sq.Clear(); _sq.Clear();
for (int i = 0; i < Count; i++) int half = Count / 2;
for (int i = 0; i < half; i++)
{
_sq.Enqueue(new Node
{
id = i,
total = _priority[i],
});
}
for (int i = half; i < Count; i++)
{ {
_sq.Enqueue(new Node _sq.Enqueue(new Node
{ {
@ -202,13 +212,24 @@ public class PriorityQueueBenchmarks
_sq.Dequeue(); _sq.Dequeue();
} }
} }
[Benchmark] [Benchmark]
public void EnqueueDequeue_RcBinaryMinHeap() public void EnqueueDequeue_RcBinaryMinHeap()
{ {
_bmHeap.Clear(); _bmHeap.Clear();
for (int i = 0; i < Count; i++) int half = Count / 2;
for (int i = 0; i < half; i++)
{
_bmHeap.Push(new Node
{
id = i,
total = _priority[i],
});
}
for (int i = half; i < Count; i++)
{ {
_bmHeap.Push(new Node _bmHeap.Push(new Node
{ {
@ -218,13 +239,15 @@ public class PriorityQueueBenchmarks
_bmHeap.Pop(); _bmHeap.Pop();
} }
} }
[Benchmark] [Benchmark]
public void EnqueueDequeue_PriorityQueue() public void EnqueueDequeue_PriorityQueue()
{ {
_pq.Clear(); _pq.Clear();
for (int i = 0; i < Count; i++) int half = Count / 2;
for (int i = 0; i < half; i++)
{ {
var node = new Node var node = new Node
{ {
@ -232,7 +255,16 @@ public class PriorityQueueBenchmarks
total = _priority[i], total = _priority[i],
}; };
_pq.Enqueue(node, node); _pq.Enqueue(node, node);
}
for (int i = half; i < Count; i++)
{
var node = new Node
{
id = i,
total = _priority[i],
};
_pq.Enqueue(node, node);
_pq.Dequeue(); _pq.Dequeue();
} }
} }