CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2000
    Location
    Israel
    Posts
    33

    .NET data structure efficiency

    Hi all,

    When I moved to .NET I found out that all my Stl data structure where slown down. I wrote a little demo and find out that the same code run faster on Visual 6. I compared CArray Vs std::vector and my results were as following

    CArray in .Net (atl::carray ? ) is 20% slower then in Visual 6 ( mfc::CArray ).

    std::vector in .Net is 50% slower then in Visual 6.

    Do the data structures I checked are much slower or did I do something wrong ???

    Thanks, udi

    p.s. here is the code I tested ( concole application using MFC )

    Code:
    // MfcVsStl.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    #include 
    #include "MfcVsStl.h"
    
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif
    
    /////////////////////////////////////////////////////////////////////////////
    // The one and only application object
    
    CWinApp theApp;
    #include 
    
    using namespace std;
    class CMyClass
    {
    public:
    	CMyClass()
    	{
    		m_myIntMember = 0;
    		m_myString = "";
    		m_myArray.RemoveAll();
    	}
    	
    	CMyClass(const CMyClass & other )
    	{
    		*this = other;
    	}
    	
    	CMyClass & operator = (const CMyClass & other )
    	{
    		m_myIntMember = other.m_myIntMember;
    		m_myString = other.m_myString;
    
    		m_myArray.RemoveAll();
    		int dummy;
    		for (int i=0 ; i m_myArray;
    	CString m_myString;
    };
    typedef std::vector MyClassVecotr;	
    int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
    {
    	int nRetCode = 0;
    
    	// initialize MFC and print and error on failure
    	if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
    	{
    		// TODO: change error code to suit your needs
    		cerr << _T("Fatal Error: MFC initialization failed") << endl;
    		nRetCode = 1;
    	}
    	else
    	{
    		// TODO: code your application's behavior here.
    		CMyClass myClass;
    		myClass.m_myIntMember = 23847143;
    
    		for ( int i=0 ; i<1000 ; i++ )
    		{
    			myClass.m_myArray.Add(i);
    		}
    
    		myClass.m_myString = "Why is .Net so slow ???";
    		CArray udi;
    		
    		MyClassVecotr udi2;
    		DWORD time1 = GetTickCount();
    		for ( i=0 ; i<500 ; i++)
    		{
    			udi2.push_back(myClass);
    		}
    
    		DWORD total2 = GetTickCount() - time1;
    		int dummy2 = 0;
    		
    		time1 = GetTickCount();
    		for ( i=0 ; i<500 ; i++)
    			{
    			udi.Add(myClass);
    			}
    
    		DWORD total = GetTickCount() - time1;
    		int dummy = 0;
    	}
    
    	return nRetCode;
    }

  2. #2
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    I heard about this issue several times already - mainly that most of the applications which gets updated to .NET are running slower than their equivalent compiled on Visual Studio 6.0.

    I did not test it myself so I am still unsure whether it is right or not. I assume that you compiled unmanaged code with .NET though otherwise this might be responsible for the performance decrease...

  3. #3
    Join Date
    Jun 2002
    Location
    Germany
    Posts
    1,557

    Getting slowed down

    Hello,

    I often engage in run-time studies for pure number-crunching applications running in the emulated DOS console for both VC6 as well as VC7. The case studies involve various ultra-high precision calculations (such as 10^6 decimal digits of pi) written in highly-optimized C++ with a pure-C engine for FFT multiplication.

    The test cases are written in pure C/C++ with no MFC support and no managed C++ support. The run-time critical algorithms do not typically make significant use of the STL.

    The run-time performance of the code generated by VC7 is about 10% faster than VC6. GCC running in pure Linux without X-Windows is always about another 10% faster. I came to the conclusion that the optimizing compilers of VC7 are superior to those of VC6. This observation has been confirmed by test-runs using several other types of console applications.

    Unfortunately, I do not have detailed results for the implementation of STL-vectors. However, I did make the observation (using a character-based, nested factorial calculation) that the implementation of ::std::string in VC7 is very fast---faster than VC6 and even faster than GCC 3.2.

    I believe that there must be some run-time issues associated with the common language run-time environment for managed C++ and C# applications. The constraints put on the compiler are especially challenging for managed C++. If you look at the compiled assembler code for managed C++, you will find that although the compiler produces valid x86 assembly in Debug mode, the compiler creates pseudo-code for the common language run-time environment (CLR) in Release mode. In particular, the assembly files contain the comment: "; Generated by VC++ for Common Language Runtime".

    The CLR probably needs a lot of work. However, it is unclear wheter or not optimized run-time characteristics are an established development goal for the .NET platform.

    Chris.

    Last edited by dude_1967; January 7th, 2003 at 06:07 AM.
    You're gonna go blind staring into that box all day.

  4. #4
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: Getting slowed down

    Originally posted by dude_1967
    Hello,

    I often engage in run-time studies for pure number-crunching applications running in the emulated DOS console for both VC6 as well as VC7. The case studies involve various ultra-high precision calculations (such as 10^6 decimal digits of pi) written in highly-optimized C++ with a pure-C engine for FFT multiplication.

    <snipped>
    Thank you very much for providing this useful information.

    From what I get from your post you cannot verify any speed decrease of .NET for at least your kind of application. That is what I basically expected but I read and heard many other stories about that.

    I am in the process to get .NET running to perform some testings myself but your results are looking optimistic...

  5. #5
    Join Date
    Jun 2002
    Location
    Germany
    Posts
    1,557

    Common Language Runtime (CLR) and IL

    Andreas,

    I believe that managed C++ and C# are compiled not into target-based assembler, but rather into the new Microsoft intermediate assembly language (IL) which is a type of assembler-like pseudo code. The IL pseudocode can be interpreted within the common language runtime (CLR).

    These programs run slow.

    Pure, non-managed C++ is just fine---with, in fact significantly improved run-time performance compared with VC6, SP5. There are indications that the implementation of the STL-containers is well-optimized for run-time performance.

    You can expect good run-time performance for your applications as long as you do not program the time-critical sequences using managed C++ or C#. I would like to find out about your experiences in this matter if you get a chance to do any performance testing.

    Sincerely,
    Chris.

    P.S. There is a book which I intend to order soon. It seems to describe the IL and its role in the CLR:

    http://www.amazon.com/exec/obidos/AS...695143-8556656
    You're gonna go blind staring into that box all day.

  6. #6
    Join Date
    Dec 2002
    Location
    La Plata, Buenos Aires
    Posts
    615

    mmx

    anybody knows if VC7 can generate MMX/SSE/3DNow code automatically? (in either managed or unmanaged mode?)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured