Why does .NET Array.Sort suck so bad...

Mark R

Diamond Member
Oct 9, 1999
8,513
16
81
Sorting ints

Sorted 16777216 items in 9796.875 ms using Array.Sort
Sorted 16777216 items in 6609.375 ms using explicitly coded quicksort (CLR)
Press any key to continue

Sorting floats

Sorted 1048576 items in 16609.375 ms using Array.Sort
Sorted 1048576 items in 375 ms using explicitly coded quicksort (CLR)
Press any key to continue

Sorting doubles

Sorted 1048576 items in 16796.875 ms using Array.Sort
Sorted 1048576 items in 390.625 ms using explicitly coded quicksort (CLR)
Press any key to continue

So, while sorting ints isn't bad - sorting floats/doubles is shocking.

What's up?
 

beggerking

Golden Member
Jan 15, 2006
1,703
0
0
I'd guess its .net garbage collection / type checking at work..
another reason to go to school to become a programmer; built-in function are almost never optimzed for performance rather than compatibility.
 

tfinch2

Lifer
Feb 3, 2004
22,114
1
0
If I'm sorting that many items and performance counts, you better believe I'm not going to use the built in sort functions.
 

MrChad

Lifer
Aug 22, 2001
13,507
3
81
What version of .NET are you using? Have you tried the same test in other versions?