Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio C# 2010 Express Debug running Faster than Release

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.

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.

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.

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.

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?

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);
                }
            }

        }
    }
}

}

EDIT:: 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.

like image 387
Nomad101 Avatar asked Sep 06 '12 22:09

Nomad101


People also ask

Can I use Visual Studio for C?

Visual Studio Code is a lightweight, cross-platform development environment that runs on Windows, Mac, and Linux systems. The Microsoft C/C++ for Visual Studio Code extension supports IntelliSense, debugging, code formatting, auto-completion. Visual Studio for Mac doesn't support Microsoft C++, but does support .

Is Visual Studio C or C++?

The Visual Studio IDE supports C++ development on Windows, Linux, Android and iOS with a code editor, debugger, test frameworks, static analyzers, and other programming tools.

How do I get C in Visual Studio?

Download & Install the C/C++ Extension We need to click on the extension button that displays a sidebar for downloading and installing the C/C++ extension in the visual studio code. In the sidebar, type C Extension. In this image, click on the Install button to install the C/C++ extension.

What is Visual C studio?

Visual Studio is an Integrated Development Environment (IDE), meaning it contains a sosurce code editor for writing programs, a compiler for compiling source code into an executable program, and a run time environment in which you can run and debug programs.


1 Answers

I don't see anything in there to say that you are selecting release build. This is an option on the toolbar. If you are directly running a debug build maybe it is looking for something it can't find.

EDIT: except the title which I missed!!!! :-)

like image 101
MikeKulls Avatar answered Nov 15 '22 11:11

MikeKulls