是.NET 4.0运行时慢于.NET 2.0运行时? [英] Are .NET 4.0 Runtime slower than .NET 2.0 Runtime?

查看:188
本文介绍了是.NET 4.0运行时慢于.NET 2.0运行时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我升级我的项目到.NET 4.0(含VS2010)我意识到比他们的运行速度比他们在.NET 2.0(VS2008)慢。所以我决定基准在两个VS2008与放一个简单的控制台应用程序; VS2010与各目标框架:

After I upgraded my projects to .NET 4.0 (With VS2010) I realized than they run slower than they were in .NET 2.0 (VS2008). So i decided to benchmark a simple console application in both VS2008 & VS2010 with various Target Frameworks:

using System;
using System.Diagnostics;
using System.Reflection;

namespace RuntimePerfTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(Assembly.GetCallingAssembly().ImageRuntimeVersion);
            Stopwatch sw = new Stopwatch();

            while (true)
            {
                sw.Reset();
                sw.Start();

                for (int i = 0; i < 1000000000; i++)
                {

                }

                TimeSpan elapsed = sw.Elapsed;
                Console.WriteLine(elapsed);
            }
        }
    }
}

下面是结果:

  • 在VS2008
    • 目标框架2.0:〜0.25秒
    • 目标框架3.0:〜0.25秒
    • 目标框架3.5:〜0.25秒
    • VS2008
      • Target Framework 2.0: ~0.25 seconds
      • Target Framework 3.0: ~0.25 seconds
      • Target Framework 3.5: ~0.25 seconds
      • 目标框架2.0:〜3.8秒
      • 目标框架3.0:〜3.8秒
      • 目标框架3.5:〜1.51秒
      • 目标框架3.5客户端配置文件:〜3.8秒
      • 目标框架4.0:〜1.01秒
      • 目标Framework 4.0客户端配置文件:〜1.01秒

      我的初步结论显然是与VS2008的工作比VS2010编译的程序更快编译的程序。

      My initial conclusion is obviously that programs compiled with VS2008 working faster than programs compiled with VS2010.

      谁能解释VS2008和VS2010之间的性能变化?和不同的目标框架内VS2010本身?

      Can anyone explain those performance changes between VS2008 and VS2010? and between different Target Frameworks inside VS2010 itself?

      推荐答案

      我想我已经知道了。

      如果你是一个64位的机器上运行,确保构建设置为任何CPU,而不是86。这样做,我的机器上解决了该问题。

      If you're running on a 64 bit machine, make sure the build is set to "Any CPU" rather than "x86". Doing that fixed the issue on my machine.

      默认为VS2010改变新项目从任何CPU到86 - 我相信这是使编辑并继续默认工作在64位机器(因为它仅支持x86)

      The default for new projects changed in VS2010 from "Any CPU" to "x86" - I believe this was to make Edit and Continue work by default on 64 bit machines (as it only supports x86).

      <打击>在64位计算机上运行的x86的过程显然是有些不理想。

      编辑:作为每达斯汀的评论时,运行86而不是64可以具有在更有效地利用存储器方面的性能优点(更短的引用)

      As per Dustin's comments, running x86 rather than x64 can have performance advantages in terms of more efficient use of memory (shorter references).

      我也对应了与达斯汀有关此事的邮件,他包括这些原因:

      I also corresponded with Dustin about this by email, and he included these reasons:

      FWIW,默认的目标平台   不变化为支持ENC。我们有   已经发货ENC破64的   2版本。因此,通过本身,ENC不是   真是一个令人信服的理由来切换。   我们切换的主要原因(在无   特别的顺序)为:

      FWIW, the default target platform wasn’t changed to support ENC. We had already shipped ENC broken on x64 for 2 releases. So by itself, ENC wasn’t really a compelling reason to switch. The primary reasons we switched (in no particular order) were:

          
      • 的IntelliTrace不支持在x64。因此,最酷的新   功能将不会在x64 Windows的工作   任何CPU的项目。

      • IntelliTrace is not supported on x64. So, one of the coolest new features won’t work on x64 Windows for Any CPU projects.

      64位的EXE在x64 Windows上运行速度低于86的EXE执行。因此,X86的想法   调试,64位版本将意味着   优化的发布版本会   实际表现更差。

      x64 EXEs run slower on x64 Windows than x86 EXEs do. So, the idea of x86 debug, x64 release would mean that "optimized" builds in Release would actually perform worse.

      客户投诉部署一个应用程序,并发现它时,   不工作,即使它制作   他们的机器。这些人往往左右   P /调用,但没有任何其他许多   可以在一个作出的假设   应用程序,它可以打破运行时   用不同的位数。

      Customer complaints when deploying an application and finding that it doesn’t work, even though it worked on their machine. These were often around P/Invoke, but there any many other assumptions that can be made in an application that can break when run with different bitness.

      加上上述原因   事实上,一个任何CPU带来不   福利(即你不能真正拿   利用扩展的地址的   空间,因为EXE可能仍然运行在   86)是原因,默认   是切换。

      The above reasons coupled with the fact that an Any CPU brings no benefits (i.e. you can’t actually take advantage of the expanded address space because the EXE may still run on x86) was the reason that the default was switched.

      里克·拜尔斯有   有关此主题的优秀帖子   <一href="http://blogs.msdn.com/rmbyers/archive/2009/06/8/anycpu-exes-are-usually-more-trouble-then-they-re-worth.aspx">here.

      Rick Byers has an excellent post on this topic here.

      这篇关于是.NET 4.0运行时慢于.NET 2.0运行时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆