473,507 Members | 12,693 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

exectution speed and debugging output

Hi again,

I need a suggestion.

Right now I am developing an application and I want to be able to
output on screen some variables. Anyway, I want to remove these output
operations when passing on the implementation of another function or
finiship up the program etc.. Still I whish to be able to have the
output again in case I will need to do some debugging in the future
(very likely!).

Now I pass to each function a bool parameter "show" and then, inside
the function:

if(show) output some stuff.

I suppose that this if-statement slows down the code a lot (and the
program MUST be fast), for instance because the compiler cannot
optimize not knowing the value of the show flag at runtime. Is that
correct?

What is the best way then to have this control over debugging output?
Should I use the preprocessor with a #define and then #ifdef /
#ifndef?

I'm happy to learn :)

Apr 1 '07 #1
15 1668
Giff wrote:
Hi again,

[redacted]

Now I pass to each function a bool parameter "show" and then, inside
the function:

if(show) output some stuff.

I suppose that this if-statement slows down the code a lot
Why do you suppose this? Have you benchmarked and profiled?
(and the program MUST be fast),
Why? What are your requirements? Have you benchmarked and tested to
see if you meet your requirements?

Hoare's Law (also attributed to Knuth): "Premature optimization is the
root of all evil".

Apr 1 '07 #2
On 1 Apr, 16:38, red floyd <no.s...@here.dudewrote:
I suppose that this if-statement slows down the code a lot

Why do you suppose this?
well I thought that whenever there is an if, the compiler will have a
bit harder life to optimize the code
>Have you benchmarked and profiled?
No
>
(and the program MUST be fast),

Why? What are your requirements?
interactivity
Have you benchmarked and tested to
see if you meet your requirements?
I am in the middle of it, too early to check.
>
Hoare's Law (also attributed to Knuth): "Premature optimization is the
root of all evil".
Well I think "premature" is quite a flexible word, maybe it is
premature in my case, but consider my question as general.
Apr 1 '07 #3
"Giff" <Gi******@gmail.comwrote in message
news:11**********************@e65g2000hsc.googlegr oups.com...
Hi again,

I need a suggestion.

Right now I am developing an application and I want to be able to
output on screen some variables. Anyway, I want to remove these output
operations when passing on the implementation of another function or
finiship up the program etc.. Still I whish to be able to have the
output again in case I will need to do some debugging in the future
(very likely!).

Now I pass to each function a bool parameter "show" and then, inside
the function:

if(show) output some stuff.

I suppose that this if-statement slows down the code a lot (and the
program MUST be fast), for instance because the compiler cannot
optimize not knowing the value of the show flag at runtime. Is that
correct?
I would suspect that the if statment would execute as 2 machine
instructions, something like:

MOV AX, [show]
JNZ AX,[someaddress]

This should execute fairly fast. Even if it was some other type of
comparison,

if ( a b )

it would only be 3 assemtly instructions or so, something like:

MOV AX,[a]
MOV BX,[b]
JGT [someaddress]

The JGT may be more like
JGT AX,BX,[someaddress]

or something. I haven't looked at assembly language isntructions since the
386 days.

In other words, I wouldn't worry about the execution speed.
What is the best way then to have this control over debugging output?
Should I use the preprocessor with a #define and then #ifdef /
#ifndef?
Some people do that.
I'm happy to learn :)

Apr 1 '07 #4
On Apr 1, 3:48 pm, "Giff" <Giffn...@gmail.comwrote:
Right now I am developing an application and I want to be able to
output on screen some variables. Anyway, I want to remove these output
operations when passing on the implementation of another function or
finiship up the program etc.. Still I whish to be able to have the
output again in case I will need to do some debugging in the future
(very likely!).
Now I pass to each function a bool parameter "show" and then, inside
the function:
if(show) output some stuff.
This sort of thing is more often handled by a global variable.
(It's one of the rare cases where a global variable is
appropriate.)
I suppose that this if-statement slows down the code a lot (and the
program MUST be fast), for instance because the compiler cannot
optimize not knowing the value of the show flag at runtime. Is that
correct?
No. The difference in speed is hardly noticeable.
What is the best way then to have this control over debugging output?
Should I use the preprocessor with a #define and then #ifdef /
#ifndef?
In general, I find some sort of logging class, invoked via
macros, to be preferable. Historically, I'd try to design the
macros so that they could be replaced with an empty string, if
performance issues required. In practice, they never did, and I
don't worry about it today.

--
James Kanze (Gabi Software) email: ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Apr 1 '07 #5
James Kanze ha scritto:
This sort of thing is more often handled by a global variable.
(It's one of the rare cases where a global variable is
appropriate.)
That's right.

>
No. The difference in speed is hardly noticeable.
Ok. My supposition was that with a if statement it would not be possible
to use the pipeline of the processor since the next operation depends by
the current one. Where am I wrong?

In general, I find some sort of logging class, invoked via
macros, to be preferable. Historically, I'd try to design the
macros so that they could be replaced with an empty string, if
performance issues required. In practice, they never did, and I
don't worry about it today.
Thanks for the tips, I however try to not use macros at all.
Apr 1 '07 #6
Jim Langston ha scritto:
>
if ( a b )

it would only be 3 assemtly instructions or so, something like:

MOV AX,[a]
MOV BX,[b]
JGT [someaddress]
Sorry, my knowledge of assembly is very limited, but where is the
condition checked?
Apr 1 '07 #7

Giff wrote:
>>
No. The difference in speed is hardly noticeable.

Ok. My supposition was that with a if statement it would not be possible
to use the pipeline of the processor since the next operation depends by
the current one. Where am I wrong?
I'll reply to myself: the next operation IS known at compile time!!
Apr 1 '07 #8
Giff wrote:
>No. The difference in speed is hardly noticeable.


Ok. My supposition was that with a if statement it would not be possible
to use the pipeline of the processor since the next operation depends by
the current one. Where am I wrong?
User interactions are required to occur in milliseconds. 'if'
operations occur in nanoseconds. So you're not wrong, only a factor of
a million or so from being relevant.

--
Scott McPhillips [VC++ MVP]

Apr 1 '07 #9
"Giff" <gi******@gmail.com.invalidwrote in message
news:eu**********@aioe.org...
Jim Langston ha scritto:
>>
if ( a b )

it would only be 3 assemtly instructions or so, something like:

MOV AX,[a]
MOV BX,[b]
JGT [someaddress]

Sorry, my knowledge of assembly is very limited, but where is the
condition checked?
JGT Jump if Greater Than
Apr 1 '07 #10

"Giff" <gi******@gmail.com.invalidwrote in message
news:eu**********@aioe.org...
Jim Langston ha scritto:
>>
if ( a b )

it would only be 3 assemtly instructions or so, something like:

MOV AX,[a]
MOV BX,[b]
JGT [someaddress]

Sorry, my knowledge of assembly is very limited, but where is the
condition checked?
The 'check' statement is the 'JGT' instruction
(presumably means something like "Jump if Greater than".)

-Mike
Apr 1 '07 #11
Scott McPhillips [MVP] ha scritto:
User interactions are required to occur in milliseconds. 'if'
operations occur in nanoseconds. So you're not wrong, only a factor of
a million or so from being relevant.
:)

somehow I thought that that bool would have been set at runtime, but it
isn't, silly me
Apr 1 '07 #12
Jim Langston ha scritto:
>
JGT Jump if Greater Than
thanks
Apr 1 '07 #13
On 1 Apr., 22:12, "Mike Wahler" <mkwah...@mkwahler.netwrote:
"Giff" <giffn...@gmail.com.invalidwrote in message

news:eu**********@aioe.org...
Jim Langston ha scritto:
if ( a b )
it would only be 3 assemtly instructions or so, something like:
MOV AX,[a]
MOV BX,[b]
JGT [someaddress]
Sorry, my knowledge of assembly is very limited, but where is the
condition checked?

The 'check' statement is the 'JGT' instruction
(presumably means something like "Jump if Greater than".)

-Mike
The problem is the comparison was forgotten. The relevant instruction
is CMP AX,BX.
Probably the code would be implemented soemthing like

MOV AX,[a]
CMP ax,[b]
JGT [someaddress]

(but this is off-topic)

/Peter

Apr 1 '07 #14
On Apr 1, 9:35 pm, Giff <giffn...@gmail.com.invalidwrote:
James Kanze ha scritto:
[...]
No. The difference in speed is hardly noticeable.
Ok. My supposition was that with a if statement it would not be possible
to use the pipeline of the processor since the next operation depends by
the current one. Where am I wrong?
Most processors today have some form of branch prediction, and
will avoid flushing the pipeline in the msot frequent case
(where tracing is turned off). Even on an old 8086, the
"pipeline" was only flushed if the jump was taken, and compilers
rearranged the code so that the most frequent (or the fastest)
case didn't take the branch.

(Obviously, when tracing is on, the formatting and output take
several orders of magnitude more time than that lost in loosing
the pipeline.)
In general, I find some sort of logging class, invoked via
macros, to be preferable. Historically, I'd try to design the
macros so that they could be replaced with an empty string, if
performance issues required. In practice, they never did, and I
don't worry about it today.
Thanks for the tips, I however try to not use macros at all.
Logging is one place where they are almost always the rule.
Amongst other things, you want to get __FILE__ and __LINE__ in
the log, automatically, and you can only do that with a macro.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Apr 2 '07 #15
On Apr 1, 10:17 pm, Giff <giffn...@gmail.com.invalidwrote:
Scott McPhillips [MVP] ha scritto:
User interactions are required to occur in milliseconds. 'if'
operations occur in nanoseconds. So you're not wrong, only a factor of
a million or so from being relevant.
:)
somehow I thought that that bool would have been set at runtime, but it
isn't, silly me
But it is, normally. Somewhere at the beginning of the program,
you will test if the option -D has been given, or if some
specific environment variable has been set, or in larger
projects, read a configuration file. And it is important that
the condition be relatively rapid if tracing is turned off (and
there is no user output). Relatively---you're still doing a lot
of other things in the code. So, for example, my code can even
support multiple if's in a single trace statement, but it would
not be acceptable to format the complete output into a string,
and just not write it.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Apr 2 '07 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2944
by: Rob Ristroph | last post by:
I have tried out PHP 5 for the first time (with assistance from this group -- thanks!). The people I was working with have a site that uses lots of php objects. They are having problems with...
1
3811
by: jim.eggleston | last post by:
I just figured out a reasonably decent way to use pdb in SciTE for debugging Python scripts. Debugging takes place in the SciTE output window. I have only tested this with SciTE on Windows. Here...
5
3612
by: snicks | last post by:
I'm trying to exec a program external to my ASP.NET app using the following code. The external app is a VB.NET application. Dim sPPTOut As String sPPTOut = MDEPDirStr + sID + ".ppt" Dim p As...
2
1213
by: Larry Goldstein | last post by:
I have just recompiled several of my large projects under VS2005 and notice that the speed at which they operate within the Debug configuration has gone up by a factor of 300-400%. Does anyone know...
102
4437
by: tom fredriksen | last post by:
Hi I was doing a simple test of the speed of a "maths" operation and when I tested it I found that removing the loop that initialises the data array for the operation caused the whole program to...
4
1667
by: ASP Developer | last post by:
I have a strange bug with visual studio.net 2005. When I click the stop debugging button my web application will end but before it does it executes all of the code vs exiting on the line I am...
5
1413
by: =?Utf-8?B?U3RlZmFuIEJhcmxvdw==?= | last post by:
I am experiencing a lot of speed issues on initial app loads where we are referencing 3rd party 1.1 assemblies from 2.0 code. Those 1.1 assemblies reference things like System.Windows.Forms...
11
2633
by: =?Utf-8?B?S3VlaXNoaW9uZyBUdQ==?= | last post by:
I am running Visual studio 2003 with framework 1.1 on a vista platform. However it runs very slow in debug mode, especially while it is loading dlls. What is the problem? Is there a compatibility...
87
3649
by: pereges | last post by:
I have a C program which I created on Windows machine. I have compiled and executed the program on windows machine and it gives me the consistent output every time i run it. for eg. input a = 2,...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7314
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7030
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7482
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5041
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1540
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
411
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.