exulateution速度和调试输出 [英] exectution speed and debugging output

查看:85
本文介绍了exulateution速度和调试输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨再次,


我需要一个建议。


现在我正在开发一个应用程序,我希望能够

在屏幕上输出一些变量。无论如何,我想删除这些输出

操作时传递另一个函数的执行或

完成程序等等。仍然我想能够拥有

再次输出,以防我将来需要做一些调试

(非常可能!)。


现在我将bool参数show传递给每个函数。然后,里面

函数:


if(show)输出一些东西。


我想这个这个if语句会慢慢减慢代码(并且

程序必须很快),例如因为编译器不能优化
优化不知道show flag的值在运行时。那是

是否正确?


控制调试输出的最佳方法是什么?

我应该使用预处理器用#define然后#ifdef /

#ifndef?


我很乐意学习:)

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 :)

推荐答案

Giff写道:
Giff wrote:

再次





现在我向每个函数传递一个bool参数show然后,里面

函数:


if(show)输出一些东西。


我想这个这个if语句会慢慢减慢代码的速度
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),



为什么?你有什么要求?你有没有基准测试和测试

看你是否满足你的要求?


Hoare'定律(也归功于Knuth):过早优化是

所有邪恶的根源。

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".


4月1日16:38,red floyd< no.s。 .. @ here.dudewrote:
On 1 Apr, 16:38, red floyd <no.s...@here.dudewrote:

我想这个if语句会慢慢减慢代码
I suppose that this if-statement slows down the code a lot



你为什么这么想?


Why do you suppose this?



我认为只要有if,编译器就会有更难的生活来优化代码

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(也归功于Knuth):过早优化是所有邪恶的根源。
>
Hoare''s Law (also attributed to Knuth): "Premature optimization is the
root of all evil".



我认为过早这是一个非常灵活的词,也许在我的情况下是早期的b / b,但我认为我的问题是一般的。

Well I think "premature" is quite a flexible word, maybe it is
premature in my case, but consider my question as general.


" Giff" < Gi ****** @ gmail.com写信息

新闻:11 ********************** @ e65g2000hsc .googlegr oups.com ...
"Giff" <Gi******@gmail.comwrote in message
news:11**********************@e65g2000hsc.googlegr oups.com...

嗨再次,


我需要一个建议。


现在我正在开发一个应用程序,我希望能够在屏幕上输出一些变量的
。无论如何,我想删除这些输出

操作时传递另一个函数的执行或

完成程序等等。仍然我想能够拥有

再次输出,以防我将来需要做一些调试

(非常可能!)。


现在我将bool参数show传递给每个函数。然后,里面

函数:


if(show)输出一些东西。


我想这个这个if语句会慢慢减慢代码(并且

程序必须很快),例如因为编译器不能优化
优化不知道show flag的值在运行时。那是

是否正确?
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?



我怀疑if语句将作为2台机器执行

指令,类似于:


MOV AX,[show]

JNZ AX,[someaddress]


这应该执行得相当快。即使它是某种其他类型的

比较,


if(ab)


它只会是3个装配说明左右,如:


MOV AX,[a]

MOV BX,[b]

JGT [someaddress]


JGT可能更像是

JGT AX,BX,[someaddress]


或一些东西。自从

386天以来,我没有看过汇编语言的结构。


换句话说,我不担心执行速度。

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.


控制调试输出的最佳方法是什么?

我应该使用预处理器和#define然后# ifdef /

#ifndef?
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 :)



这篇关于exulateution速度和调试输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆