Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Performance / November 2003

Tip: Looking for answers? Try searching our database.

Fast Sorting

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nick - 12 Nov 2003 18:43 GMT
Hi !

Does anyone know when there will be a faster
implementation of Sorting in c#, because sorting
of only 300 Strings is extremly slow. And implementing
sorting for objects via CompareTo is also much too
slow because you have to cast the object to access
the member which is to be sorted.

thanks,
nick
Sherif ElMetainy - 12 Nov 2003 20:08 GMT
Hello

The default sorting for string uses String.Compare which is slow because it
uses culture information to compare string.
Better use String.CompareOrdinal if you use english strings only or don't
want culture specific sorting.

Best regards
Sherif

> Hi !
>
[quoted text clipped - 7 lines]
> thanks,
> nick
Jon Skeet [C# MVP] - 12 Nov 2003 22:07 GMT
> Does anyone know when there will be a faster
> implementation of Sorting in c#, because sorting
> of only 300 Strings is extremly slow. And implementing
> sorting for objects via CompareTo is also much too
> slow because you have to cast the object to access
> the member which is to be sorted.

Casting is pretty fast. If you need to box/unbox, that takes a lot
longer.

When you say that sorting 300 strings is "extremely slow", what exactly
do you mean? As another poster mentioned, using CompareOrdinal speeds
things up considerably - on my machine I can sort an array of 300
strings 100,000 times in 10 seconds, which certainly doesn't sound
"extremely slow" to me.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Gang Peng[MSFT] - 19 Nov 2003 19:59 GMT
Yes. If you don't care about cultural issues, you should try ordinal
comparison as Jon suggested.

Generics will solve the problems of boxing/unboxing and casting, but you
need to wait for Whidbey.

Gang Peng
[MS]

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.