Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PriorityQueue Performance Improvements #48520

Closed

Conversation

eiriktsarpalis
Copy link
Member

  • Use ref locals to minimize copying.
  • Use binary heap instead of quad heap.

Performance

PriorityQueue<string, string> master

Method Size Mean Error StdDev Median Min Max Gen 0 Gen 1 Gen 2 Allocated
HeapSort 10 2,611.00 ns 8.444 ns 7.052 ns 2,611.19 ns 2,600.34 ns 2,627.39 ns 0.0102 - - 184 B
Enumerate 10 72.67 ns 0.229 ns 0.192 ns 72.70 ns 72.44 ns 73.11 ns - - - -
Dequeue_And_Enqueue 10 6,096.25 ns 31.858 ns 26.603 ns 6,100.84 ns 6,058.37 ns 6,150.80 ns - - - -
K_Max_Elements 10 1,044.18 ns 3.508 ns 2.929 ns 1,044.35 ns 1,040.08 ns 1,048.28 ns - - - -
HeapSort 100 53,774.03 ns 354.994 ns 332.061 ns 53,640.10 ns 53,357.79 ns 54,367.37 ns - - - 1,624 B
Enumerate 100 546.87 ns 3.405 ns 3.185 ns 548.12 ns 542.14 ns 551.77 ns - - - -
Dequeue_And_Enqueue 100 136,928.79 ns 953.871 ns 796.526 ns 137,022.70 ns 135,407.61 ns 137,808.38 ns - - - -
K_Max_Elements 100 7,905.11 ns 176.800 ns 181.560 ns 7,855.12 ns 7,750.50 ns 8,401.73 ns - - - -
HeapSort 1000 937,339.23 ns 5,962.281 ns 4,978.774 ns 937,926.47 ns 930,112.87 ns 945,493.01 ns - - - 16,024 B
Enumerate 1000 5,279.45 ns 62.309 ns 48.647 ns 5,267.58 ns 5,220.51 ns 5,390.56 ns - - - -
Dequeue_And_Enqueue 1000 2,094,658.28 ns 8,643.392 ns 7,217.624 ns 2,092,575.45 ns 2,082,779.91 ns 2,108,681.70 ns - - - -
K_Max_Elements 1000 52,082.79 ns 191.983 ns 149.888 ns 52,112.34 ns 51,799.58 ns 52,358.94 ns - - - -

PriorityQueue<string, string> PR branch

Method Size Mean Error StdDev Median Min Max Gen 0 Gen 1 Gen 2 Allocated
HeapSort 10 2,211.85 ns 15.005 ns 12.530 ns 2,218.12 ns 2,192.54 ns 2,226.37 ns 0.0168 - - 184 B
Enumerate 10 65.52 ns 0.587 ns 0.521 ns 65.57 ns 64.77 ns 66.34 ns - - - -
Dequeue_And_Enqueue 10 4,765.44 ns 41.396 ns 36.696 ns 4,761.79 ns 4,701.92 ns 4,829.89 ns - - - -
K_Max_Elements 10 963.72 ns 7.120 ns 5.945 ns 962.09 ns 955.55 ns 974.95 ns - - - -
HeapSort 100 51,196.04 ns 349.304 ns 309.649 ns 51,191.60 ns 50,808.62 ns 51,738.70 ns - - - 1,624 B
Enumerate 100 516.26 ns 3.538 ns 2.954 ns 517.23 ns 510.62 ns 519.38 ns - - - -
Dequeue_And_Enqueue 100 131,836.99 ns 852.135 ns 755.396 ns 131,449.37 ns 131,133.69 ns 133,232.38 ns - - - -
K_Max_Elements 100 7,478.26 ns 78.705 ns 65.722 ns 7,480.90 ns 7,317.46 ns 7,574.62 ns - - - -
HeapSort 1000 1,001,641.24 ns 17,086.617 ns 15,982.832 ns 995,504.88 ns 981,357.62 ns 1,035,606.84 ns - - - 16,024 B
Enumerate 1000 5,041.03 ns 56.957 ns 50.490 ns 5,032.40 ns 4,952.18 ns 5,146.67 ns - - - -
Dequeue_And_Enqueue 1000 2,275,478.60 ns 32,725.267 ns 30,611.235 ns 2,275,954.91 ns 2,232,071.88 ns 2,333,933.48 ns - - - -
K_Max_Elements 1000 55,057.58 ns 1,054.213 ns 1,035.378 ns 55,031.64 ns 53,621.49 ns 57,047.04 ns - - - -

PriorityQueue<int, int> master

Method Size Mean Error StdDev Median Min Max Gen 0 Gen 1 Gen 2 Allocated
HeapSort 10 169.47 ns 0.900 ns 0.751 ns 169.33 ns 168.41 ns 170.90 ns 0.0097 - - 104 B
Enumerate 10 26.55 ns 0.157 ns 0.139 ns 26.50 ns 26.38 ns 26.82 ns - - - -
Dequeue_And_Enqueue 10 457.64 ns 1.449 ns 1.284 ns 457.89 ns 454.77 ns 459.06 ns - - - -
K_Max_Elements 10 131.32 ns 0.985 ns 0.873 ns 130.89 ns 130.36 ns 132.93 ns - - - -
HeapSort 100 2,615.30 ns 13.750 ns 11.481 ns 2,610.16 ns 2,600.54 ns 2,642.96 ns 0.0741 - - 824 B
Enumerate 100 222.15 ns 0.900 ns 0.798 ns 222.29 ns 220.83 ns 223.72 ns - - - -
Dequeue_And_Enqueue 100 8,660.31 ns 43.103 ns 40.319 ns 8,664.44 ns 8,589.11 ns 8,719.59 ns - - - -
K_Max_Elements 100 484.06 ns 1.310 ns 1.162 ns 484.07 ns 481.37 ns 485.96 ns - - - -
HeapSort 1000 70,389.28 ns 351.348 ns 311.460 ns 70,368.25 ns 69,935.17 ns 70,822.62 ns 0.5605 - - 8,024 B
Enumerate 1000 2,106.86 ns 9.027 ns 7.047 ns 2,104.82 ns 2,099.36 ns 2,123.09 ns - - - -
Dequeue_And_Enqueue 1000 167,413.64 ns 741.954 ns 657.723 ns 167,205.49 ns 166,672.34 ns 169,095.15 ns - - - -
K_Max_Elements 1000 3,237.06 ns 12.555 ns 9.802 ns 3,236.94 ns 3,219.13 ns 3,251.88 ns - - - -

PriorityQueue<int, int> PR branch

Method Size Mean Error StdDev Median Min Max Gen 0 Gen 1 Gen 2 Allocated
HeapSort 10 162.60 ns 1.048 ns 0.929 ns 162.51 ns 160.61 ns 163.72 ns 0.0100 - - 104 B
Enumerate 10 25.82 ns 0.157 ns 0.147 ns 25.79 ns 25.62 ns 26.12 ns - - - -
Dequeue_And_Enqueue 10 356.76 ns 1.211 ns 0.945 ns 356.85 ns 354.63 ns 357.91 ns - - - -
K_Max_Elements 10 111.33 ns 2.927 ns 3.254 ns 112.46 ns 107.46 ns 116.50 ns - - - -
HeapSort 100 2,976.04 ns 46.222 ns 43.236 ns 2,967.98 ns 2,897.63 ns 3,052.82 ns 0.0719 - - 824 B
Enumerate 100 214.92 ns 1.697 ns 1.588 ns 214.44 ns 212.79 ns 217.43 ns - - - -
Dequeue_And_Enqueue 100 8,814.66 ns 47.681 ns 42.268 ns 8,813.03 ns 8,742.95 ns 8,890.31 ns - - - -
K_Max_Elements 100 431.95 ns 4.789 ns 4.245 ns 430.47 ns 426.30 ns 440.54 ns - - - -
HeapSort 1000 78,828.54 ns 2,119.835 ns 2,356.191 ns 78,350.61 ns 75,256.64 ns 84,025.36 ns 0.6068 - - 8,024 B
Enumerate 1000 2,053.21 ns 30.037 ns 25.083 ns 2,045.93 ns 2,019.22 ns 2,096.44 ns - - - -
Dequeue_And_Enqueue 1000 159,890.95 ns 1,384.848 ns 1,227.631 ns 159,836.84 ns 157,858.65 ns 162,027.53 ns - - - -
K_Max_Elements 1000 3,142.46 ns 24.237 ns 22.671 ns 3,138.93 ns 3,104.62 ns 3,183.90 ns - - - -

@ghost
Copy link

ghost commented Feb 19, 2021

Tagging subscribers to this area: @eiriktsarpalis
See info in area-owners.md if you want to be subscribed.

Issue Details
  • Use ref locals to minimize copying.
  • Use binary heap instead of quad heap.

Performance

PriorityQueue<string, string> master

Method Size Mean Error StdDev Median Min Max Gen 0 Gen 1 Gen 2 Allocated
HeapSort 10 2,611.00 ns 8.444 ns 7.052 ns 2,611.19 ns 2,600.34 ns 2,627.39 ns 0.0102 - - 184 B
Enumerate 10 72.67 ns 0.229 ns 0.192 ns 72.70 ns 72.44 ns 73.11 ns - - - -
Dequeue_And_Enqueue 10 6,096.25 ns 31.858 ns 26.603 ns 6,100.84 ns 6,058.37 ns 6,150.80 ns - - - -
K_Max_Elements 10 1,044.18 ns 3.508 ns 2.929 ns 1,044.35 ns 1,040.08 ns 1,048.28 ns - - - -
HeapSort 100 53,774.03 ns 354.994 ns 332.061 ns 53,640.10 ns 53,357.79 ns 54,367.37 ns - - - 1,624 B
Enumerate 100 546.87 ns 3.405 ns 3.185 ns 548.12 ns 542.14 ns 551.77 ns - - - -
Dequeue_And_Enqueue 100 136,928.79 ns 953.871 ns 796.526 ns 137,022.70 ns 135,407.61 ns 137,808.38 ns - - - -
K_Max_Elements 100 7,905.11 ns 176.800 ns 181.560 ns 7,855.12 ns 7,750.50 ns 8,401.73 ns - - - -
HeapSort 1000 937,339.23 ns 5,962.281 ns 4,978.774 ns 937,926.47 ns 930,112.87 ns 945,493.01 ns - - - 16,024 B
Enumerate 1000 5,279.45 ns 62.309 ns 48.647 ns 5,267.58 ns 5,220.51 ns 5,390.56 ns - - - -
Dequeue_And_Enqueue 1000 2,094,658.28 ns 8,643.392 ns 7,217.624 ns 2,092,575.45 ns 2,082,779.91 ns 2,108,681.70 ns - - - -
K_Max_Elements 1000 52,082.79 ns 191.983 ns 149.888 ns 52,112.34 ns 51,799.58 ns 52,358.94 ns - - - -

PriorityQueue<string, string> PR branch

Method Size Mean Error StdDev Median Min Max Gen 0 Gen 1 Gen 2 Allocated
HeapSort 10 2,211.85 ns 15.005 ns 12.530 ns 2,218.12 ns 2,192.54 ns 2,226.37 ns 0.0168 - - 184 B
Enumerate 10 65.52 ns 0.587 ns 0.521 ns 65.57 ns 64.77 ns 66.34 ns - - - -
Dequeue_And_Enqueue 10 4,765.44 ns 41.396 ns 36.696 ns 4,761.79 ns 4,701.92 ns 4,829.89 ns - - - -
K_Max_Elements 10 963.72 ns 7.120 ns 5.945 ns 962.09 ns 955.55 ns 974.95 ns - - - -
HeapSort 100 51,196.04 ns 349.304 ns 309.649 ns 51,191.60 ns 50,808.62 ns 51,738.70 ns - - - 1,624 B
Enumerate 100 516.26 ns 3.538 ns 2.954 ns 517.23 ns 510.62 ns 519.38 ns - - - -
Dequeue_And_Enqueue 100 131,836.99 ns 852.135 ns 755.396 ns 131,449.37 ns 131,133.69 ns 133,232.38 ns - - - -
K_Max_Elements 100 7,478.26 ns 78.705 ns 65.722 ns 7,480.90 ns 7,317.46 ns 7,574.62 ns - - - -
HeapSort 1000 1,001,641.24 ns 17,086.617 ns 15,982.832 ns 995,504.88 ns 981,357.62 ns 1,035,606.84 ns - - - 16,024 B
Enumerate 1000 5,041.03 ns 56.957 ns 50.490 ns 5,032.40 ns 4,952.18 ns 5,146.67 ns - - - -
Dequeue_And_Enqueue 1000 2,275,478.60 ns 32,725.267 ns 30,611.235 ns 2,275,954.91 ns 2,232,071.88 ns 2,333,933.48 ns - - - -
K_Max_Elements 1000 55,057.58 ns 1,054.213 ns 1,035.378 ns 55,031.64 ns 53,621.49 ns 57,047.04 ns - - - -

PriorityQueue<int, int> master

Method Size Mean Error StdDev Median Min Max Gen 0 Gen 1 Gen 2 Allocated
HeapSort 10 169.47 ns 0.900 ns 0.751 ns 169.33 ns 168.41 ns 170.90 ns 0.0097 - - 104 B
Enumerate 10 26.55 ns 0.157 ns 0.139 ns 26.50 ns 26.38 ns 26.82 ns - - - -
Dequeue_And_Enqueue 10 457.64 ns 1.449 ns 1.284 ns 457.89 ns 454.77 ns 459.06 ns - - - -
K_Max_Elements 10 131.32 ns 0.985 ns 0.873 ns 130.89 ns 130.36 ns 132.93 ns - - - -
HeapSort 100 2,615.30 ns 13.750 ns 11.481 ns 2,610.16 ns 2,600.54 ns 2,642.96 ns 0.0741 - - 824 B
Enumerate 100 222.15 ns 0.900 ns 0.798 ns 222.29 ns 220.83 ns 223.72 ns - - - -
Dequeue_And_Enqueue 100 8,660.31 ns 43.103 ns 40.319 ns 8,664.44 ns 8,589.11 ns 8,719.59 ns - - - -
K_Max_Elements 100 484.06 ns 1.310 ns 1.162 ns 484.07 ns 481.37 ns 485.96 ns - - - -
HeapSort 1000 70,389.28 ns 351.348 ns 311.460 ns 70,368.25 ns 69,935.17 ns 70,822.62 ns 0.5605 - - 8,024 B
Enumerate 1000 2,106.86 ns 9.027 ns 7.047 ns 2,104.82 ns 2,099.36 ns 2,123.09 ns - - - -
Dequeue_And_Enqueue 1000 167,413.64 ns 741.954 ns 657.723 ns 167,205.49 ns 166,672.34 ns 169,095.15 ns - - - -
K_Max_Elements 1000 3,237.06 ns 12.555 ns 9.802 ns 3,236.94 ns 3,219.13 ns 3,251.88 ns - - - -

PriorityQueue<int, int> PR branch

Method Size Mean Error StdDev Median Min Max Gen 0 Gen 1 Gen 2 Allocated
HeapSort 10 162.60 ns 1.048 ns 0.929 ns 162.51 ns 160.61 ns 163.72 ns 0.0100 - - 104 B
Enumerate 10 25.82 ns 0.157 ns 0.147 ns 25.79 ns 25.62 ns 26.12 ns - - - -
Dequeue_And_Enqueue 10 356.76 ns 1.211 ns 0.945 ns 356.85 ns 354.63 ns 357.91 ns - - - -
K_Max_Elements 10 111.33 ns 2.927 ns 3.254 ns 112.46 ns 107.46 ns 116.50 ns - - - -
HeapSort 100 2,976.04 ns 46.222 ns 43.236 ns 2,967.98 ns 2,897.63 ns 3,052.82 ns 0.0719 - - 824 B
Enumerate 100 214.92 ns 1.697 ns 1.588 ns 214.44 ns 212.79 ns 217.43 ns - - - -
Dequeue_And_Enqueue 100 8,814.66 ns 47.681 ns 42.268 ns 8,813.03 ns 8,742.95 ns 8,890.31 ns - - - -
K_Max_Elements 100 431.95 ns 4.789 ns 4.245 ns 430.47 ns 426.30 ns 440.54 ns - - - -
HeapSort 1000 78,828.54 ns 2,119.835 ns 2,356.191 ns 78,350.61 ns 75,256.64 ns 84,025.36 ns 0.6068 - - 8,024 B
Enumerate 1000 2,053.21 ns 30.037 ns 25.083 ns 2,045.93 ns 2,019.22 ns 2,096.44 ns - - - -
Dequeue_And_Enqueue 1000 159,890.95 ns 1,384.848 ns 1,227.631 ns 159,836.84 ns 157,858.65 ns 162,027.53 ns - - - -
K_Max_Elements 1000 3,142.46 ns 24.237 ns 22.671 ns 3,138.93 ns 3,104.62 ns 3,183.90 ns - - - -
Author: eiriktsarpalis
Assignees: eiriktsarpalis
Labels:

area-System.Collections

Milestone: 6.0.0

if (_comparer == null)
{
MoveUpDefaultComparer((element, priority), lastNodeIndex);
MoveUpDefaultComparer(ref item, _size - 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried making similar ref changes and didn't see it have a measurable impact on string,string or int,int. Do you see a benefit? I imagine the benefit may be larger for larger data types; did you try that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are marginal improvements, but largely the impact in the benchmarks came from moving to a binary heap. I will need to include more benchmarks using struct types.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

largely the impact in the benchmarks came from moving to a binary heap

That would be my expectation as well.

I suggest separating the changes and measuring them on their own merit separately.

@@ -247,32 +236,28 @@ public TElement EnqueueDequeue(TElement element, TPriority priority)
{
if (_size != 0)
{
(TElement Element, TPriority Priority) root = _nodes[RootIndex];
ref (TElement Element, TPriority Priority) root = ref _nodes[0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: can you name the locals that are refs to have a "Ref" suffix, e.g. "rootRef"? Otherwise it's easy to accidentally write over something you weren't expecting.

@@ -44,12 +44,12 @@ public class PriorityQueue<TElement, TPriority>
/// Specifies the arity of the d-ary heap, which here is quaternary.
/// It is assumed that this value is a power of 2.
/// </summary>
private const int Arity = 4;
private const int Arity = 2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there other simplifications we could make if we hardcoded this into the code itself rather than it being configurable via these consts? e.g. rather than looping through all the children, just knowing that there are only two.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would definitely eliminate a couple of extra calculations, but I wanted to measure the impact of just changing the constant value first.

@danmoseley
Copy link
Member

cc @pgolebiowski

@danmoseley
Copy link
Member

There's some regressions above as well as improvements (eg Heap_Sort in most cases). Is this a net win?

@pgolebiowski
Copy link
Contributor

pgolebiowski commented Feb 19, 2021

@eiriktsarpalis if a binary heap is in general better than a 4-ary heap, let's change it, but bear in mind that it's not straightforward to prove.

In this paper, where there are ~40 scenarios considered and about a dozen of heap implementations, it's sometimes the binary heap that is more performant and sometimes the 4-ary heap. I encourage you to make a more diverse set of benchmarks to build what "the general case" is. I think that without this our performance optimizations may be biased towards the testing strategy, which may not reflect the general case appropriately.

@eiriktsarpalis
Copy link
Member Author

Ok, so I reverted the branch back to quad heap to present an apples-to-apples comparison. I've added PriorityQueue<Guid,Guid> to the benchmark to measure performance in larger values.

The results seem inconclusive. The differences in numbers seem to fluctuate across BDN runs and do not signal a notable change in performance. The PriorityQueue<Guid, Guid> numbers are pretty unremarkable, I would have expected more gains with larger structs.

PriorityQueue<int,int>

master

Method Size Mean Error StdDev Median Min Max Gen 0 Gen 1 Gen 2 Allocated
HeapSort 10 162.95 ns 6.409 ns 7.124 ns 164.03 ns 152.15 ns 175.63 ns 0.0101 - - 104 B
Enumerate 10 27.02 ns 1.186 ns 1.365 ns 26.50 ns 25.27 ns 29.46 ns - - - -
Dequeue_And_Enqueue 10 448.21 ns 14.338 ns 16.511 ns 449.18 ns 426.58 ns 492.89 ns - - - -
K_Max_Elements 10 130.69 ns 3.525 ns 3.918 ns 130.41 ns 125.03 ns 139.15 ns - - - -
HeapSort 100 2,573.83 ns 105.896 ns 121.950 ns 2,545.82 ns 2,438.11 ns 2,829.15 ns 0.0718 - - 824 B
Enumerate 100 223.34 ns 9.997 ns 11.512 ns 219.42 ns 211.12 ns 241.42 ns - - - -
Dequeue_And_Enqueue 100 8,945.09 ns 344.606 ns 396.849 ns 8,707.12 ns 8,592.38 ns 9,732.61 ns - - - -
K_Max_Elements 100 492.71 ns 24.542 ns 28.262 ns 475.13 ns 469.32 ns 550.77 ns - - - -
HeapSort 1000 71,654.67 ns 2,686.414 ns 3,093.679 ns 70,020.04 ns 68,821.83 ns 79,041.27 ns 0.5531 - - 8,024 B
Enumerate 1000 2,090.82 ns 64.590 ns 69.111 ns 2,060.00 ns 2,034.20 ns 2,246.02 ns - - - -
Dequeue_And_Enqueue 1000 175,344.57 ns 7,855.787 ns 9,046.737 ns 172,121.50 ns 166,461.82 ns 195,755.37 ns - - - -
K_Max_Elements 1000 3,318.50 ns 133.854 ns 154.147 ns 3,238.97 ns 3,182.87 ns 3,647.75 ns - - - -

PR branch

Method Size Mean Error StdDev Median Min Max Gen 0 Gen 1 Gen 2 Allocated
HeapSort 10 159.92 ns 1.227 ns 1.148 ns 159.98 ns 157.85 ns 161.90 ns 0.0098 - - 104 B
Enumerate 10 25.51 ns 0.187 ns 0.175 ns 25.47 ns 25.26 ns 25.87 ns - - - -
Dequeue_And_Enqueue 10 403.99 ns 2.756 ns 2.443 ns 403.27 ns 400.35 ns 409.55 ns - - - -
K_Max_Elements 10 105.81 ns 0.301 ns 0.267 ns 105.75 ns 105.49 ns 106.40 ns - - - -
HeapSort 100 2,657.67 ns 30.114 ns 26.695 ns 2,651.03 ns 2,623.52 ns 2,712.98 ns 0.0732 - - 824 B
Enumerate 100 217.60 ns 4.314 ns 3.602 ns 217.87 ns 212.84 ns 225.41 ns - - - -
Dequeue_And_Enqueue 100 8,395.92 ns 140.174 ns 124.261 ns 8,390.73 ns 8,127.19 ns 8,582.35 ns - - - -
K_Max_Elements 100 504.94 ns 28.058 ns 31.186 ns 490.95 ns 472.70 ns 575.10 ns - - - -
HeapSort 1000 76,030.92 ns 3,192.438 ns 3,676.416 ns 74,178.74 ns 72,995.88 ns 84,172.17 ns 0.6127 - - 8,024 B
Enumerate 1000 2,072.91 ns 65.064 ns 72.318 ns 2,037.55 ns 2,011.96 ns 2,248.70 ns - - - -
Dequeue_And_Enqueue 1000 174,543.10 ns 7,025.296 ns 8,090.341 ns 172,693.52 ns 166,840.03 ns 189,262.03 ns - - - -
K_Max_Elements 1000 3,268.14 ns 149.993 ns 172.732 ns 3,157.28 ns 3,099.61 ns 3,568.27 ns - - - -

PriorityQueue<string,string>

master

Method Size Mean Error StdDev Median Min Max Gen 0 Gen 1 Gen 2 Allocated
HeapSort 10 2,615.17 ns 78.071 ns 89.906 ns 2,570.17 ns 2,526.15 ns 2,814.32 ns 0.0108 - - 184 B
Enumerate 10 71.17 ns 2.837 ns 3.267 ns 70.31 ns 67.23 ns 76.08 ns - - - -
Dequeue_And_Enqueue 10 5,970.18 ns 119.156 ns 105.629 ns 5,960.05 ns 5,837.86 ns 6,169.47 ns - - - -
K_Max_Elements 10 1,086.04 ns 48.513 ns 55.868 ns 1,055.70 ns 1,040.13 ns 1,189.65 ns - - - -
HeapSort 100 57,743.80 ns 2,498.448 ns 2,877.217 ns 57,062.36 ns 54,605.52 ns 62,752.85 ns - - - 1,624 B
Enumerate 100 507.84 ns 19.976 ns 23.004 ns 497.61 ns 482.59 ns 548.01 ns - - - -
Dequeue_And_Enqueue 100 136,435.97 ns 5,750.287 ns 6,622.039 ns 133,843.41 ns 129,527.36 ns 151,767.33 ns - - - -
K_Max_Elements 100 7,836.43 ns 334.915 ns 385.689 ns 7,617.28 ns 7,488.63 ns 8,784.59 ns - - - -
HeapSort 1000 945,379.18 ns 43,023.464 ns 49,545.885 ns 914,841.41 ns 906,001.37 ns 1,054,753.71 ns - - - 16,024 B
Enumerate 1000 4,994.86 ns 261.318 ns 300.934 ns 4,885.05 ns 4,700.94 ns 5,630.32 ns - - - -
Dequeue_And_Enqueue 1000 2,210,783.27 ns 96,973.722 ns 107,786.035 ns 2,149,183.04 ns 2,105,598.21 ns 2,410,114.29 ns - - - -
K_Max_Elements 1000 56,920.24 ns 2,537.538 ns 2,922.232 ns 54,859.98 ns 54,583.00 ns 62,765.15 ns - - - -

PR branch

Method Size Mean Error StdDev Median Min Max Gen 0 Gen 1 Gen 2 Allocated
HeapSort 10 2,852.85 ns 215.679 ns 230.774 ns 2,767.39 ns 2,615.39 ns 3,426.13 ns 0.0099 - - 184 B
Enumerate 10 75.20 ns 5.229 ns 6.021 ns 75.27 ns 67.09 ns 84.10 ns - - - -
Dequeue_And_Enqueue 10 6,117.85 ns 441.680 ns 508.639 ns 6,238.57 ns 5,519.76 ns 6,948.69 ns - - - -
K_Max_Elements 10 1,186.73 ns 92.733 ns 106.792 ns 1,119.25 ns 1,080.88 ns 1,365.52 ns - - - -
HeapSort 100 55,761.48 ns 921.830 ns 862.280 ns 55,811.29 ns 54,268.66 ns 57,613.66 ns - - - 1,624 B
Enumerate 100 441.82 ns 5.632 ns 4.703 ns 441.83 ns 435.53 ns 450.95 ns - - - -
Dequeue_And_Enqueue 100 129,825.70 ns 3,389.216 ns 3,626.423 ns 127,786.37 ns 126,504.51 ns 139,966.50 ns - - - -
K_Max_Elements 100 8,363.42 ns 46.862 ns 39.132 ns 8,358.56 ns 8,291.69 ns 8,428.63 ns - - - -
HeapSort 1000 936,186.74 ns 16,728.584 ns 14,829.454 ns 933,275.55 ns 923,176.65 ns 974,366.73 ns - - - 16,024 B
Enumerate 1000 4,094.78 ns 33.848 ns 28.265 ns 4,086.56 ns 4,067.56 ns 4,156.46 ns - - - -
Dequeue_And_Enqueue 1000 2,094,971.05 ns 65,638.115 ns 72,956.591 ns 2,072,580.47 ns 1,997,964.84 ns 2,245,423.44 ns - - - -
K_Max_Elements 1000 50,690.73 ns 1,557.285 ns 1,730.918 ns 50,031.23 ns 48,279.77 ns 54,357.49 ns - - - -

PriorityQueue<Guid ,Guid>

master

Method Size Mean Error StdDev Median Min Max Gen 0 Gen 1 Gen 2 Allocated
HeapSort 10 267.82 ns 13.886 ns 15.992 ns 271.03 ns 251.14 ns 295.12 ns 0.0341 - - 344 B
Enumerate 10 34.17 ns 1.406 ns 1.619 ns 33.75 ns 32.00 ns 36.92 ns - - - -
Dequeue_And_Enqueue 10 677.23 ns 11.478 ns 9.585 ns 675.63 ns 666.95 ns 700.10 ns - - - -
K_Max_Elements 10 228.27 ns 4.426 ns 3.456 ns 226.85 ns 225.84 ns 236.82 ns - - - -
HeapSort 100 5,774.89 ns 206.538 ns 237.850 ns 5,637.37 ns 5,561.30 ns 6,188.55 ns 0.3080 - - 3,224 B
Enumerate 100 289.38 ns 11.013 ns 12.683 ns 281.95 ns 279.56 ns 312.03 ns - - - -
Dequeue_And_Enqueue 100 16,558.99 ns 462.867 ns 495.262 ns 16,316.76 ns 16,160.48 ns 17,950.16 ns - - - -
K_Max_Elements 100 1,354.76 ns 66.063 ns 76.078 ns 1,332.87 ns 1,276.22 ns 1,553.37 ns - - - -
HeapSort 1000 122,817.32 ns 4,353.606 ns 5,013.619 ns 120,604.39 ns 117,957.75 ns 131,552.82 ns 2.8195 - - 32,024 B
Enumerate 1000 2,816.08 ns 104.617 ns 120.477 ns 2,736.10 ns 2,714.25 ns 3,018.51 ns - - - -
Dequeue_And_Enqueue 1000 286,110.98 ns 10,726.424 ns 12,352.566 ns 278,460.61 ns 276,386.85 ns 311,311.21 ns - - - -
K_Max_Elements 1000 7,854.71 ns 273.875 ns 315.395 ns 7,697.74 ns 7,560.66 ns 8,477.79 ns - - - -

PR branch

Method Size Mean Error StdDev Median Min Max Gen 0 Gen 1 Gen 2 Allocated
HeapSort 10 256.42 ns 4.931 ns 4.612 ns 254.66 ns 250.05 ns 263.91 ns 0.0339 - - 344 B
Enumerate 10 31.17 ns 0.306 ns 0.255 ns 31.15 ns 30.82 ns 31.80 ns - - - -
Dequeue_And_Enqueue 10 731.85 ns 7.292 ns 5.693 ns 733.34 ns 721.95 ns 739.21 ns - - - -
K_Max_Elements 10 204.27 ns 4.345 ns 4.462 ns 203.54 ns 199.35 ns 217.36 ns - - - -
HeapSort 100 5,610.80 ns 44.716 ns 41.828 ns 5,616.40 ns 5,551.59 ns 5,680.67 ns 0.3000 - - 3,224 B
Enumerate 100 284.59 ns 3.873 ns 3.434 ns 283.83 ns 278.64 ns 290.71 ns - - - -
Dequeue_And_Enqueue 100 19,976.03 ns 1,168.299 ns 1,345.414 ns 19,546.82 ns 18,414.61 ns 22,873.74 ns - - - -
K_Max_Elements 100 1,053.99 ns 80.190 ns 92.347 ns 1,040.40 ns 948.32 ns 1,233.38 ns - - - -
HeapSort 1000 120,395.93 ns 1,663.203 ns 1,555.761 ns 120,626.00 ns 118,004.75 ns 122,518.22 ns 2.7778 - - 32,024 B
Enumerate 1000 2,812.40 ns 137.714 ns 147.353 ns 2,778.73 ns 2,642.02 ns 3,057.93 ns - - - -
Dequeue_And_Enqueue 1000 325,418.01 ns 26,634.655 ns 30,672.508 ns 323,724.71 ns 272,894.34 ns 368,107.08 ns - - - -
K_Max_Elements 1000 7,669.74 ns 567.895 ns 653.988 ns 7,573.41 ns 6,667.90 ns 8,892.75 ns - - - -

@eiriktsarpalis
Copy link
Member Author

Since the benchmarks are inconclusive, I'm going to close this for now. I will follow-up with another PR cherry picking the unrelated fixes I've incorporated here.

@ghost ghost locked as resolved and limited conversation to collaborators Mar 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants