High performance sorting algorithm

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I've written a C++ program years ago, it's still in use in the company where
I work, now its time to port it to .net, preferable managed code. However,
I'm a little concerned about a sorting performance. I need to sort a somewhat
high number of entries in a list. I think of using generics with an
IComparable interface. Are the sorting alogirith available in .net
efficient?. What kind of performance hit can I expect in managed code
compared to unmanaged?

Regards Jesper
 
I used a generic List to sort data displyed in a BindingList and that was
almost instantaneous with 50,000 records

hth

Guy
 
I've written a C++ program years ago, it's still in use in the company where
I work, now its time to port it to .net, preferable managed code. However,
I'm a little concerned about a sorting performance. I need to sort a somewhat
high number of entries in a list. I think of using generics with an
IComparable interface. Are the sorting alogirith available in .net
efficient?. What kind of performance hit can I expect in managed code
compared to unmanaged?

..NET Array.Sort performance is poor when called with an IComparer. Sorting
an array of 1,000,000 integers without IComparer takes .4 sec on my machine,
and with IComparer, it takes 10 sec, a 25 to 1 performance hit. I coded a VB
quicksort algorithm to do the same thing, I ran it in debug mode, and it took
..8 sec. It was implemented without an IComparer, but it did call a Test()
function for every compare.

Array.Sort without IComparer is fast, with IComparer it is not so good.
Apparently, using the IComparer interface is expensive.
 
AMercer said:
.NET Array.Sort performance is poor when called with an IComparer. Sorting
an array of 1,000,000 integers without IComparer takes .4 sec on my machine,
and with IComparer, it takes 10 sec, a 25 to 1 performance hit. I coded a VB
quicksort algorithm to do the same thing, I ran it in debug mode, and it took
.8 sec. It was implemented without an IComparer, but it did call a Test()
function for every compare.

Array.Sort without IComparer is fast, with IComparer it is not so good.
Apparently, using the IComparer interface is expensive.

Are you talking about the non-generic IComparer interface? If so, it
would be boxing the integer every time it called you - that would be
slow indeed.
 
Back
Top