.NET Framework Bookmark and Share   
 index > 64-Bit .NET Framework Development > 64-bit SortedDictionary class over 3x slower than 32-bit version?
 

64-bit SortedDictionary class over 3x slower than 32-bit version?

I'm seeing a 3x-10x performance slowdown using the SortedDictionary class in 64-bit CLR. I posted a longer thread earlier but just deleted it, since I now understand the problem in more detail and have a much shorter repro case (included below) so wanted to start fresh.

The code below runs at least 3x slower on an 8-wayx86 server than all the 32-bit PCs I tried including a beefy 4-way Xeon server and a low-end workstation. I can create variations on this code which run even slower, but figured simpler is better for now.

CLR experts-- is this expected? Could there be something else causing the problem besides 64 vs. 32 bit, e.g. 8-way vs. 4-way? Note that I haven't seensimilar variations with other CLR classes, only SortedDictionary. The problem doesn't occur with smaller-sized dictionaries, only larger ones. (My test uses 20K items)

using System;

using System.Collections.Generic;

class Program

{

static void Main(string[] args)

{

Console.WriteLine("Starting perf test of SortedDictionary");

Random rand = new Random();

DateTime start = DateTime.Now;

int nTotalDictionaries = 500, dictSize = 20000, nTotalItems = 0;

for (int j = 0; j < nTotalDictionaries; j++)

{

SortedDictionary<int, bool> dict = new SortedDictionary<int, bool>();

for (int i = 0, nLen = dictSize; i < nLen; i++, nTotalItems++)

{

// get a new index, and make sure it's not taken already

int newNumber;

for (newNumber=rand.Next(1,1000000); dict.ContainsKey(newNumber);newNumber=rand.Next(1,1000000))

;

dict.Add(newNumber, true); // add it

}

}

Console.WriteLine ("Running in {0}-bit mode", IntPtr.Size * 8);

TimeSpan elapsed = (DateTime.Now - start);

Console.WriteLine("Loaded {0} total items, into {1} SortedDictionary instances in {2} seconds",

nTotalItems, nTotalDictionaries, elapsed.TotalMilliseconds / 1000.0);

Console.WriteLine("press any key to continue");

Console.ReadKey();

}

}

justingrant

Hi justingrant,

I test your code on a 4core xeon system, and I can get a similar result like you said, x64-8.x s and x86-7.x s.

Thanks for your valuable feedback. You may also submit it to the following site in the formal way:

http://connect.microsoft.com/VisualStudio/.

Thanks!

Feng Chen

Hi justingrant,

Have you post this issue to our Connect feedback portal?

If you have submitted it, we will appreciate it if you can share the feedback address so that it can be found and checked out by other community members having similar issues.

Thank you!

Feng Chen

Hi Feng- I'm not sure I understand. Are you saying you tried this code and it took 8 seconds on x64 and 7 seconds on x86?That would be surprisinggiven that I'm seeing a perf difference of 3x-- although the only x64 system I have is an AMD system, while all the x86 systems I tested on were Intel, so this might be an Intel vs. AMD thing rather than an x86 vs. x64 problem.

I have not reported this on Connect yet, have beenbusy... :-)

justingrant

You can use google to search for other answers

Custom Search

More Threads

• Help needed for beginner
• Setting the Platform to x64 in VS2005 for a ASP.NET web site type project
• 64-bit Apps Directory on the web
• Porting from 32-bit to 64-bit
• Making the jump to a 64 bit development machine
• Unable to open the offline cache location..
• Running x86 UserControl in TestContainer failed under Vista x64
• Processors
• 32bit build gives error, 64bit does not (and vice versa)
• 64 bit problem