?
Solved

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

Posted on 2003-03-22
2
Medium Priority
?
277 Views
Last Modified: 2008-02-01
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 !
0
Comment
Question by:pcooke
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 8

Expert Comment

by:fl0yd
ID: 8188245
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
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 375 total points
ID: 8189453
I got the same results.
To see why this happens debug TRACE and afxDump lines.
TRACE is executed using single call to unsafe but fast function of class CTraceFileAndLineInfo:

void __cdecl operator()(const char *pszFmt, ...) const

afxDump line is series of calls to overloaded

CDumpContext& CDumpContext ::operator<<

operators.

The line:
afxDump << "Loop " << dwLoop << "\n";

actually calls 3 overloaded << operators with parameters:
LPCTSTR
DWORD_PTR
LPCTSTR

LPCTSTR operator contains also some loops. All this, together with type conversions and returning reference to CDumpContext object, gets the time.

Time difference is the difference between unsafe and fast C-style TRACE implememtation and safe and slow C++ style CDumpContext implementation.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question