Blog Stats
  • Posts - 99
  • Articles - 5
  • Comments - 39
  • Trackbacks - 108

 

Sorting Performance .NET 2.0

Be very careful when using Array.Sort in 2.0. I had posted a bug report about this a while ago http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=62029e14-2d0b-4250-a163-1583034db250

The behavior observed was originally in arraylist (which uses Array.Sort internally) so keep in mind that this applies to it as well.

Array.Sort(Items, 0, Items.Length, Comparer.Default); //takes 1 minute
Array.Sort(Items2, 0, Items.Length, null); //takes 250 ms

Items and Items2 are both clones of the same object []

What is tricky about this code is that the second call does not actually call Array.Sort .. it calls Array<object> .Sort

First call:

IL_0083: ldsfld class [mscorlib]System.Collections.Comparer [mscorlib]System.Collections.Comparer::Default
IL_0088: call void [mscorlib]System.Array::Sort(class [mscorlib]System.Array, int32, int32, class [mscorlib]System.Collections.IComparer)

Second Call:

IL_00c9: ldnull
IL_00ca: call void [mscorlib]System.Array::Sort (!!0[], int32, int32, class [mscorlib]System.Collections.Generic.IComparer`1)

Ah .. :)

Basically what the issue is is that there are 2 distinct sorting algorithms .. one that is Array.Sort one that is Array.Sort .. they do not use the same algorithm. From what I understand some changes were made in how pivots are chosen.


Feedback

# re: Sorting Performance .NET 2.0

Gravatar Interesting find! 5/28/2006 10:29 PM | Aaron Feng

# re: Sorting Performance .NET 2.0

Gravatar Hi dear, i read this good information and find more interest informations for you. thanks. 12/2/2007 2:54 PM | mapquest

# Indian Stock Market ShareTips/ShareTipsInfo/Intraday & Delivery Tips

Gravatar Dear Visitors,

This blog is really nice and informative. We are pleased to know this blog is really helping people. Its our pleasure to post informative content on this useful blog created by webmaster.Currently something is cooking in the Indian stock market, We know it but unfortunately we cant disclose the reason so openly. We strongly suggest everyone not to take any long position at these levels. We will see Pullback in the market very soon but that will be a fake one so don’t consider pullback as opportunity to go Long in market( Delivery based). As after that initial pullback we can see fall once again. As mentioned cant disclose it still giving minor hint see call and put section and think why you are not able to access few options and check December part and think who are the people behind it?? We suggest wait for falls to take delivery till then prefer only intraday else you will find yourself out of
BSE and NSE one fine day.For any query feel free to contact us.

Regards SHARETIPSINFO TEAM

+91- 9891655316

+91- 9899056796

+91 - 9891890425 6/9/2008 3:15 AM | ShareTipsInfo.com

Post a comment





 

Please add 3 and 5 and type the answer here:

 

 

Copyright © Greg Young