Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi all,

I was testing the runtime of some calculations with VS 2008 and .Net 3.5. Somehow unsatisfied with the result I thought I startup VS 2010 Express and try my luck with the Parallel Extensions. The first thing I've done was to copy the code to a new VS 2010 project and rerun my test. To my surprise it was by far slower than in .Net 3.5 (66 seconds, 38 seconds). I ran both tests with release builds outside the debugger. This really puzzles me as I somehow can't believe the performance drop is so great.

Here is my test code:
C#
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace SaTest
{
    class Program
    {
        struct Structure
        {
            public float X;
            public float Y;
        }


        static void Main(string[] args)
        {
            var l = new Structure[2000000];
            var r = new Random();
            for (int i = 0; i < l.Length; i++)
            {
                l[i].X = (float)(r.NextDouble() * 1000000);
                l[i].Y = (float)(r.NextDouble() * 1000000);
            }

            int counter = 0;
            double dist = 2000;
            double distSquare = dist * dist;

            var sw = new Stopwatch();
            sw.Start();
            for (int i = 0; i < l.Length; i++)
            {
                for (int j = 0; j < 2000; j++)
                {
                    double tx = l[i].X - l[j].X;
                    double ty = l[i].Y - l[j].Y;
                    if (tx * tx + ty * ty <= distSquare)
                        //if (Math.Sqrt(tx * tx + ty * ty) <= dist)
                        counter++;
                }
            }
            sw.Stop();
            Console.WriteLine(counter);
            Console.WriteLine(sw.Elapsed);
            Console.ReadLine();
        }
    }
}


Has anyone made similar experiences? Or is something weird wrong with my code? I would appreciate if anyone could test this and tell me if my results are reproducable.
Posted
Comments
Keith Barrow 3-Jul-10 16:04pm    
I don't want to answer your question, as I can't test my answer and I don't know enough about the performance of the .net 4 Frameworl. The problem is probably VS2010 sucking more resources than the earlier versions. Have you tried running the two test-rigs with VS closed?
Abhinav S 4-Jul-10 8:27am    
Did you try running the same code under release mode? Maybe that could make a difference.

1 solution

Hi,
I get identical timings when compiled with .Net 2.0, 3.5 or 4.0 in release mode with optimisations and no overflow checking. 20.76 - 20.77 seconds in all cases.

XP SP3, Intel Core 2 Duo T7250, 3GB RAM.

Alan.

P.S. I removed the vars to get the code to compile for .NET 2 and used the modified source for 3.5 and 4 as well.
 
Share this answer
 
Comments
dvtnarayana410 15-Jul-10 3:07am    
Reason for my vote of 2
avareg

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900