Link to home
Start Free TrialLog in
Avatar of pcooke
pcooke

asked on

Why is 'afxDump << etc' slower than TRACE(); in Visual C++ .net? Is it just me?

I've knocked up a quick demo app and added the following button handler:

void CafxDumpTimeTestDlg::OnBnClickedBtnStart()
{
     // TODO: Add your control notification handler code here
     DWORD dwStart = 0L;
     DWORD dwEnd = 0L;
     DWORD dwLapse = 0L;
     DWORD dwLoop = 0L;

     dwStart = ::GetTickCount();

     for(dwLoop = 0 ; dwLoop < 20 ; dwLoop++){
          afxDump << "Loop " << dwLoop << "\n";
     }

     dwEnd = ::GetTickCount();
     dwLapse = dwEnd - dwStart;

     afxDump << "==== afxDump Lapsed " << dwLapse << "\n";

     dwStart = ::GetTickCount();

     for(dwLoop = 0 ; dwLoop < 20 ; dwLoop++){
          TRACE("Loop %i\n", dwLoop);
     }

     dwEnd = ::GetTickCount();
     dwLapse = dwEnd - dwStart;

     afxDump << "==== TRACE Lapsed " << dwLapse << "\n";
}

and I get the results in the debug output window:
Loop 0
Loop 1
Loop 2
Loop 3
Loop 4
Loop 5
Loop 6
Loop 7
Loop 8
Loop 9
Loop 10
Loop 11
Loop 12
Loop 13
Loop 14
Loop 15
Loop 16
Loop 17
Loop 18
Loop 19
==== afxDump Lapsed 3575
Loop 0
Loop 1
Loop 2
Loop 3
Loop 4
Loop 5
Loop 6
Loop 7
Loop 8
Loop 9
Loop 10
Loop 11
Loop 12
Loop 13
Loop 14
Loop 15
Loop 16
Loop 17
Loop 18
Loop 19
==== TRACE Lapsed 1202


which makes 'TRACE()' maybe three times quicker than afxDump !
Avatar of fl0yd
fl0yd

Why would you care, which one is faster/slower? Those are debug-functions and won't be present in a release build anyway, so why worry?

.f
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial