Visual Studio的C#2010速成调试运行速度比快速释放 [英] Visual Studio C# 2010 Express Debug running Faster than Release

查看:506
本文介绍了Visual Studio的C#2010速成调试运行速度比快速释放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows窗体恰好与2个线程的应用程序。这些线程具有零彼此互动,阿拉巴马州第一个线程运行而不与第二个线程搞乱。它们之间没有同步,因为没有必要,要发生。与应用程序的用户界面的第一个线程交易,改变颜色和标签,并具有一个定时器运行捕捉一些用户输入的每200毫秒此计时器火灾。第二个主题是更多地参与,并通过其通过退出应用程序不断编码,直到停机的用户运行。

I have a Windows Forms application with exactly 2 threads. These threads have ZERO interaction with each other, Ala the first thread runs without messing with the second thread. There is no Synchronization between them, as there is no need for that to be happening. The first thread deals with the UI of the application, changing colors and labels and has One timer running to catch some user input this timer fires every 200 milliseconds. The second Thread is more involved and runs through its coding constantly until shutdown by the user by exiting the application.

所述第二线程首先从存储器中读取和数据存储到一个列表,然后使用该数据来作出一些计算。我有一个秒表类计时器来衡量了完成第二个线程的一次迭代的时间。这个计时器被复位和在螺纹的一开始启动,然后停止并打印到控制台一旦线程已完成一次迭代。这是我已经让我的性能数据。我一直让主题到至少1000次迭代运行,然后做不包括第一次运行的平均值。

The Second Thread first reads from memory and stores the data into a List, then uses this data to make some calculations. I have a StopWatch class timer to measure the time it takes to complete one iteration of the Second Thread. This timer is reset and started at the very beginning of the thread and then stopped and printed to console once the thread has completed an iteration. This is where I have been getting my performance data. I have been allowing the Thread to run for at least 1000 iterations and then doing an average excluding the first run.

构建的调试版本,这是一个由VSHOST运行构建或当一会按F5在Visual Studio C#2010速成。时序在0.00035s是0.35ms平均英寸

The DEBUG version of the build, that is the build that is run by the VSHOST or when one would hit F5 in Visual Studio C# 2010 Express. The Timings average in at 0.00035s that is 0.35ms.

当应用程序在VSHOST之外运行,要么按Ctrl-F5或运行从被打BUILD时所产生的.exe文件应用程序。我也用REBUILD,绝对零换乘到测试。时序在.365s是365ms平均英寸这大致与1000倍的发行版本慢。

When the application is run outside of the VSHOST, either by hitting Ctrl-F5 or by running the application from the .exe that is produced when hitting BUILD. I have also used REBUILD to test this with absolutely ZERO change. The timings average in at .365s that is 365ms. That is roughly 1000x slower with the Release Build.

我是在一个完整的无所适从是怎么回事。什么是VSHOST这样做是允许的程序,以便快速运行。我已经确定,所有的变量初始化占无误。话虽这么说,我不知道为什么这样的事情会发生。任何见解,为什么我得到这样的表现浸?

I am at a complete loss as to what is going on. What is the VSHOST doing that is allowing the program to run so quickly. I have made sure that all Variable initialization is accounted for and correct. That being said I have no clue why something like this would be happening. Any insight as to why I am getting such a performance Dip?

作为一个方面说明我现在用的电脑是64位具有超线程四核i7处理器,16千兆字节RAM和双HD6750的。因此,它似乎并不为具有太多的线程的问题,在这里,可能是一个问题的唯一事情就是超线程。

As a side note the computer I am using is 64bit has a quad core i7 with Hyper Threading, 16 Gigabytes of ram and twin HD6750's. So it does not seem to be an issue of having too many threads, the only thing here that may be an issue is the Hyper Threading.

代码中的一个片段我的应用程序做什么样的形式。然而这是不可能得到的工作代码作为存储器地址读出的是,其中慢下来时发生。

A snippet of code in the form of what my application does. However it is not possible to give working code as the memory address read is where the slow down occurs.

namespace Test Snippet
{
public struct Data
{
    public float X;
    public float Y;
    public float Z;
    public float dX;
    public float dY;

    public Data(int c)
    {
        this.X = ReadFloat(Base + 0x50 + (c * 0x10));
        this.Y = ReadFloat(Base + 0x50 + (c * 0x10));
        this.Z = ReadFloat(Base + 0x50 + (c * 0x10));
        if (this.Z == 1)
        {
            targetindex = c;
        }
        this.dX = 0;
        this.dY = 0;
    }
}
class Class1
{
    public int Base = new int();
    public List<Data> data = new List<Data>();
    public int targetindex = new int();
    public Data targetdata = new Data();

    public void GetData()
    {
        while (true)
        {
            data.Clear();
            for (int c = 0; c < 64; c++)
            {
                Data tempdata = new Data();
                teampdata = new Data(c);
                data.Add(tempdata);
            }
            if (data.Count != 0)
            {
                targetdata = data[targetindex];
                data.RemoveAt(targetindex);
                targetdata.dX = ReadFloat(Base + 0x66);
                targetdata.dY = ReadFloat(Base + 0x65);
                Data[] tempdatarray = new Data[data.Count];
                for (int j = 0; j < tempdatarray.Length; j++)
                {
                    tempdatarray[j].dX = (float)Math.Acos(targetdata.dX * 10);
                    tempdatarray[j].dY = (float)Math.Acos(targetdata.dY * 10);
                }
            }

        }
    }
}

}

:我曾尝试相同的程序,但没有使用线程。我有我所用赶用户输入的定时器称为线程函数。我得到了相同的结果。这样就意味着螺纹似乎并不成为问题。我也做了不同的计算机上测试,由于某种原因,我没有得到很大的不同。这使我相信有可能是我的电脑有点问题,或者说处理如何与我由于其超线程能力线程处理器交易。任何人都知道,如果超线程导致与未利用它明确地从程序中的多线程应用程序的问题。其中老实说,我不会有一个线索如何设置。

: I have tried the same procedure but without using threading. I had the thread function called by the Timer I was using to catch User Input. I am getting the same results. So that means that threading does not seem to be the issue. I have also done the test on a different computer and for some reason I am not getting the massive difference. Which leads me to believe there may be something wrong with my computer, or something dealing with how my processor deals with threads due to its Hyper Threading ability. Anyone know if Hyper Threading causes issues with a multi-threaded application that is not utilizing it explicitly from within the program. Which honestly I would not have a clue how to set up.

推荐答案

因此,首先,你应该做一些性能分析。无论是使用分析工具或只使用一个定时器来打印出一些消息显示地方某些事情多久 - 这应该让你至少指甲挫什么行代码运行缓慢,即使它没有告诉你为什么它的运行所以在调试器下慢得多。没有这些信息,你已经是猜测。

So first up, you should do some performance profiling. Either use a profiling tool or just use a timer to print out some messages somewhere showing how long certain things take - this should allow you to at least nail down what line of code is running slowly even if it doesn't tell you why its running so much slower under the debugger. Without this information all you have is guesswork.

现在,到了猜测...

Now, onto the guesswork...

我觉得问题牵扯到与使用控制台,基于这些观察

I think the problem has something to do with the use of the console, based on these observations


  • 写入控制台窗口本身实际上是比较慢的 - 你运行的很多东西写入控制台应用程序时可以看到这一点。如果你保持窗口打开,然后它需要很长的时间来运行,但是如果你最小化控制台窗口相同的操作可以运行的很多更快。

  • 作为我理解你正在写1消息控制台每0.35ms。那是一个许多的消息

  • 根据您如何运行你的应用程序的Visual Studio实际调试时将控制台重定向输出到输出视觉Studo内窗口

  • Writing to the console window itself is actually relatively slow - you can see this when running an application which writes a lot of stuff to the console. If you keep the window open then it takes a long time to run, however if you minimize the console window the same operation can run a lot quicker.
  • As I understand it you are writing 1 message to the console every 0.35ms. Thats a lot of messages.
  • Depending on how you are running your application Visual Studio actually redirects the console output to the "Output" window inside Visual Studo when debugging.

我的猜测是,在Visual Studio中的控制台窗口比时不进行调试使用等效机制更快了很多,那附加放缓的原因其实是你的日志代码。试着拿出你的基于控制台的日志和记录到一个文件,而不是看它是否有什么差别,甚至只是减少您例如日志消息的次数记录了完成100次迭代的时候 - 这将减少的影响(如果有的话)的控制台正对你的表现。

My guess is that the console window in Visual Studio is a lot quicker than the equivalent mechanism used when not debugging, and that the cause of the additional slowdown is actually your logging code. Try taking out your console based logging and log to a file instead to see if it makes any difference, or even just reduce the number of times you log messages e.g. log the time it takes to complete 100 iterations - this will reduce the impact (if any) that the console is having on your performance.

这篇关于Visual Studio的C#2010速成调试运行速度比快速释放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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