From cd7c668cafc1a74dfa2aa396ab49dd2ae58d7fca Mon Sep 17 00:00:00 2001 From: ikpil Date: Sun, 4 Aug 2024 18:35:25 +0900 Subject: [PATCH] changed PriorityQueueBenchmarks --- .../Benchmarks/PriorityQueueBenchmarks.cs | 38 +++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/test/DotRecast.Benchmark/Benchmarks/PriorityQueueBenchmarks.cs b/test/DotRecast.Benchmark/Benchmarks/PriorityQueueBenchmarks.cs index 93d8ab1..c4f1757 100644 --- a/test/DotRecast.Benchmark/Benchmarks/PriorityQueueBenchmarks.cs +++ b/test/DotRecast.Benchmark/Benchmarks/PriorityQueueBenchmarks.cs @@ -192,7 +192,17 @@ public class PriorityQueueBenchmarks public void EnqueueDequeue_RcSortedQueue() { _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 { @@ -202,13 +212,24 @@ public class PriorityQueueBenchmarks _sq.Dequeue(); } + } [Benchmark] public void EnqueueDequeue_RcBinaryMinHeap() { _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 { @@ -218,13 +239,15 @@ public class PriorityQueueBenchmarks _bmHeap.Pop(); } + } [Benchmark] public void EnqueueDequeue_PriorityQueue() { _pq.Clear(); - for (int i = 0; i < Count; i++) + int half = Count / 2; + for (int i = 0; i < half; i++) { var node = new Node { @@ -232,7 +255,16 @@ public class PriorityQueueBenchmarks total = _priority[i], }; _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(); } }