none
.Net 4.6 RC x64 is twice as slow as x86 (release version)! RRS feed

  • Question

  • .Net 4.6 RC x64 is twice as slow as x86 (release version):

    Consider this piece of code:

    class SpectralNorm
    	{
    		public static void Main(String[] args)
    		{
    			int n = 5500;
    			if (args.Length > 0) n = Int32.Parse(args[0]);
    
    			var spec = new SpectralNorm();
    			var watch = Stopwatch.StartNew();
    			var res = spec.Approximate(n);
    
    			Console.WriteLine("{0:f9} -- {1}", res, watch.Elapsed.TotalMilliseconds);
    		}
    
    		double Approximate(int n)
    		{
    			// create unit vector
    			double[] u = new double[n];
    			for (int i = 0; i < n; i++) u[i] = 1;
    
    			// 20 steps of the power method
    			double[] v = new double[n];
    			for (int i = 0; i < n; i++) v[i] = 0;
    
    			for (int i = 0; i < 10; i++)
    			{
    				MultiplyAtAv(n, u, v);
    				MultiplyAtAv(n, v, u);
    			}
    
    			// B=AtA         A multiplied by A transposed
    			// v.Bv /(v.v)   eigenvalue of v 
    			double vBv = 0, vv = 0;
    			for (int i = 0; i < n; i++)
    			{
    				vBv += u[i] * v[i];
    				vv += v[i] * v[i];
    			}
    
    			return Math.Sqrt(vBv / vv);
    		}
    
    
    		/* return element i,j of infinite matrix A */
    		double A(int i, int j)
    		{
    			return 1.0 / ((i + j) * (i + j + 1) / 2 + i + 1);
    		}
    
    		/* multiply vector v by matrix A */
    		void MultiplyAv(int n, double[] v, double[] Av)
    		{
    			for (int i = 0; i < n; i++)
    			{
    				Av[i] = 0;
    				for (int j = 0; j < n; j++) Av[i] += A(i, j) * v[j];
    			}
    		}
    
    		/* multiply vector v by matrix A transposed */
    		void MultiplyAtv(int n, double[] v, double[] Atv)
    		{
    			for (int i = 0; i < n; i++)
    			{
    				Atv[i] = 0;
    				for (int j = 0; j < n; j++) Atv[i] += A(j, i) * v[j];
    			}
    		}
    
    		/* multiply vector v by matrix A and then by matrix A transposed */
    		void MultiplyAtAv(int n, double[] v, double[] AtAv)
    		{
    			double[] u = new double[n];
    			MultiplyAv(n, v, u);
    			MultiplyAtv(n, u, AtAv);
    		}
    	}

    On my machine x86 release version takes 4.5 seconds to complete, while the x64 takes 9.5 seconds!

    Thursday, April 30, 2015 2:42 PM

All replies

  • Hello K28_0807,

    >>On my machine x86 release version takes 4.5 seconds to complete, while the x64 takes 9.5 seconds!

    My suggestion is that you could set time log trace for each for statement as:

    var start = DateTime.Now;
    
                for (int i = 0; i < n; i++) u[i] = 1;
    
                var watch = (DateTime.Now - start).TotalSeconds;
    
                Console.WriteLine(watch);
    

    To determine which one causes more time in the X64 environment, and if you find the detail caused reason, you could post this feedback to: https://connect.microsoft.com/VisualStudio, to let the team know this scenario.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Fred BaoModerator Friday, May 8, 2015 9:33 AM
    • Unmarked as answer by K28_0807 Tuesday, May 12, 2015 4:57 PM
    Friday, May 1, 2015 3:25 AM
    Moderator
  • This is a very important issue, please take it seriously.

    Microsoft Connect

    Stack Overflow

    Tuesday, May 12, 2015 5:00 PM
  • Details on the bug including a couple of workarounds @ https://github.com/dotnet/coreclr/issues/993#issuecomment-101805694

    Wednesday, June 3, 2015 1:19 AM