.NET 4 Parallel Programming, Not So Fast… (Part 2)

by Shelby Robertson 6. December 2009 20:11

A reader commented on my parallel programming post that the locks I used in my code were the cause of the slow performance I observed. With my implementation the locks are necessary or there is a possibility the code with fail, and it does quite often. I have done some research and it appears the optimal way to increase performance is to use one of the new System.Collections.Concurrent collections. The concurrent collections are designed to work in a multi-threaded environment when collections are going to be accessed concurrently with a minimal amount of locks. I am going to modify the existing code to use a ConcurrentBag<T> collection and will post the updated results here tomorrow.

Tags: , , , ,

.NET 4.0 | Code | LINQ | Parallel

.NET 4 Parallel Programming, Not So Fast…

by Shelby Robertson 26. August 2009 21:46

In the upcoming .NET 4 release, there are new concepts designed to help developers take advantage of the trend towards multi-core processors. This sounds like a great thing, I’m all for anything that increases performance with minimal added complexity. So we should all just run out and change all of our “foreach” loops to utilize the new framework right? I felt the need to investigate what benefits we will be getting and over the next few posts I will present and discuss my findings.

My first test was to do a very straightforward and simple comparison of an everyday task. First I generate 10,000,000 strings and put them into the list. I then iterate over the list and find all strings that match “foo”, and move them to a new list. For the results, I run this process 10 times and take the average. For this first test I decided on 4 different iteration methods: standard “foreach” loop, parallel “foreach” loop, standard LINQ query, and parallel LINQ query. I decided to also throw in the LINQ queries for two reasons. First as another comparison between standard and parallel processing and second as a comparison of LINQ to standard iteration methods. I ran the tests on a quad core AMD 9950 compiled for both 32 and 64 bit platforms.

resultsx86

Fig. 1 – 32 bit

results

 

Fig. 2 – 64 bit

The test yield some interesting results. First of all, the parallel methods didn’t win a single test. On its face this might be strange, but when you consider then simplicity of the loop and the overheard of setting up the various threads for each CPU then the results make a little more sense. The second thing is the stunning amount of time the parallel “foreach” loop takes when compiled in 32bit mode. I have no explanation for this result, but keep in mind this is the beta version of the .NET 4 framework. I will also try to run this test on an Intel box in the near future and see if the processor makes a difference.

In conclusion, I wouldn’t be preparing to go off and change all of my loops to use the parallel extensions. The loop is going to have to have a certain level of complexity before there is anything to be gained by making the switch. My goal over the next few weeks is to more thoroughly test the parallel extensions and see if I can determine at what level of complexity we she start using them. Stay tuned.

Click hereto download the Visual Studio 2010 project.

Tags: , , , , ,

Code | .NET 4.0 | LINQ

The Microsoft Lifestyle

by Shelby Robertson 20. August 2009 19:31

I came across an article today that I feel needs a response. The article, located here, tries to make the case that Apple is somehow superior to Microsoft because they have created a "lifestyle" around their product line. The author poses the question: "What is the Microsoft lifestyle?".  The answer is that the Microsoft lifestyle is to not define or constrain yourself by petty things such as "lifestyle" or "coolness". The Microsoft lifestyle is the ability to get the job done, no matter what that job is. You can't say the same thing about Apple. Most people I know that are regular Mac users also own a PC. Why do they own both? Because they need a PC to do all the things that they need to do. Necessity, quality, and cost are the factors that drive these decisions, not lifestyle. Are the sales of iPods and iPhones driven by a lifestyle? Why is Microsoft lagging behind here? It's not because of a user’s lifestyle. They are successful because they have the best products on the market in their particular markets. People don't use the Zune because it sucks, not because the iPod allows them to live some Apple lifestyle. An interesting case study will be the future of the mobile phone market. The iPhone is still the most popular phone, but the challengers are stepping up. The Palm Pre made a huge leap over it predecessor the Centro. Can you say the same thing about the last two revisions of the iPhone? Microsoft, Google, Palm, Nokia, and RIM are all targeting the iPhone. How much does lifestyle matter when the products are inferior?

Tags: , , , , , , ,

Ramblings

Welcome!

by Shelby Robertson 17. August 2009 23:51

Welcome to my site. I hope to share my expieriences as a software developer as well as publish some technical articles in effort to help the developer community. I am involved in a wide variety of technologies so topics and postings can be on pretty much any topic.

Tags:

Ramblings

Recent comments

Comment RSS

Posts by month