Very Slow Compiled Program Execution Time versus Execution Time in Visual Studio (with debugger attached)

345 views Asked by At

I have a C# executable built in Visual Studio 2019 which runs 20 times faster with debugging (F5) than without debugging (CTRL + F5) when run within Visual Studio. This happens with both the Debug and Release build options. Running the executable from the command line also produces the 20X slower run time.

That is not a typo above, I realize this is the opposite of what one would normally expect.

Any thoughts as to possible causes or avenues of investigation are welcome.

I am using the ILNumerics package for Matrix math operations, otherwise, pretty basic C# calculations (nothing fancy). Windows 10 Enterprise OS 64-bit.

1

There are 1 answers

0
Pius Zaleski On

The solution was to limit the maximum number of threads to 1 by adding the following into my Constructor method.

   ' A creatable COM class must have a Public Sub New() 
    ' with no parameters, otherwise, the class will not be 
    ' registered in the COM registry and cannot be created 
    ' via CreateObject.
    Public Sub New()
        MyBase.New()

        ILNumerics.Settings.MaxNumberThreads = 1
    End Sub