使程序更快捷的提示...... [英] Making a program quicker tips...

查看:55
本文介绍了使程序更快捷的提示......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

必须有一些提示才能让程序更快。


我猜这里超过50%的人会说避免使用if-s。是的我

知道这使得程序更快,但有时候是if

不可避免,不是吗?


有什么方法可以让程序更快?


TIA,

cmad

There must be some tips to make a program quicker.

I guess more than 50% of ppl here will say "avoid the if-s". Yeah I
know this makes a program quicker but some times an "if" is
inevitable, isn''t it?

What are some tips to make a program quicker?

TIA,
cmad

推荐答案

Chris Mantoulidis写道:
Chris Mantoulidis wrote:
什么是一些使程序更快的技巧?
What are some tips to make a program quicker?




使用更快的算法。这可以产生x%的速度增加,其中x是任意数字的
。例如,通过选择另一种算法而不是旧算法,我将速度从15分钟提高到了

100ms,就像旧的那样做了。/ b
。 br />

由于我的代码中没有做任何事情,我还设法减少了90ms的执行时间。例如,我首先将我的数组中的所有值重置为零循环开始时的
。然后我注意到我可以将

值插入到我的数组中,并将实数值后的第一个值设置为零,

并获得相同的结果,但是更短的时间。


通常它有助于找到使它变慢的原因。在你的代码中搜索缓慢的

部分,通常它是一个循环,然后考虑如何使它更快地获得
。优化所有代码通常并不聪明,因为

会降低可读性并浪费你的时间。



Use a faster algorithm. This can produce x% speed increase, where x is
any number. I have for example gained speed increase from 15 minutes to
100ms by just selecting another algorithm instead of the old one, to do
the very same thing the old did.

I also managed to drop 90ms more execution time by not doing things in
my code. For example I first reseted all values in my array to zero in
the beginning of a loop. Then I noticed that I can just insert the
values into my array, and set the first value after real values to zero,
and get the same result, but in much shorter time.

Usually it helps to find what is making it slow. Search for the slow
part in your code, usually it is a loop, and then think how to make it
faster. It isn''t usually smart to optimise all of the code, because that
decreases the readability and wastes your time.


" Chris Mantoulidis" <厘米**** @ yahoo.com>写了...
"Chris Mantoulidis" <cm****@yahoo.com> wrote...
必须有一些提示才能使程序更快。

我想这里超过50%的人会说避免使用if-s。 。是的,我知道这会使程序更快,但有时会使如果更快是不可避免的,不是吗?

有什么方法可以让程序更快?
There must be some tips to make a program quicker.

I guess more than 50% of ppl here will say "avoid the if-s". Yeah I
know this makes a program quicker but some times an "if" is
inevitable, isn''t it?

What are some tips to make a program quicker?




第一条提示:不要这样做,除非你必须这样做。


第二个提示:知道你是否必须,确保

你有某种性能要求用

可理解的术语表示,例如该程序必须在十分之一时间内完成十五次b / b $ b。


第三条提示:如果您确实有自己的要求并已准备好

以进行性能改进。你的程序,

确保你有必要的工具 - 时间点

你的程序执行,特别是找到的东西

性能瓶颈,通常将这些组合在

a工具中称为profiler。


第四提示:当然,没有真正意义上写你的

程序第一次减速,所以使用体面的算法

是必不可少的,因此,你需要学习算法来

知道哪些是在什么情况下更快。当然,在编写程序后,

,请参阅第三条提示。


第五提示:知道何时停止调整程序。你

可以追求完美,但通常是完美的,我们可以达到
。你只能在正常的生活中花费这么多,不要浪费所有这些都是虚幻的表现

改进。


我不确定你的C ++语言问题是什么。也许

下次你可以多谈一些主题。


Victor



First tip: don''t do it, unless you have to.

Second tip: to know whether you have to or not, make sure
you have some kind of performance requirement expressed in
understandable terms, like "the program has to do fifteen
summersaults in a millisecond".

Third tip: if you do have your requirements and are ready
to undertake "performance improvements" of your program,
make sure you have the necessary tools - something to time
your program''s execution and especially something to find
the performance bottlenecks, usually these are combined in
a tool called "profiler".

Fourth tip: of course, there is no real sense to write your
program slow the first time around, so using decent algos
is essential, therefore, you need to study algorithms to
know which ones are faster in what situations. Of course,
after the program is written, see Third tip.

Fifth tip: know when to stop tweaking your program. You
can strive for perfection, but usually perfection is out
of our reach. You can only do so much during a normal
lifetime, don''t waste it all on illusive performance
improvements.

I am not sure what your C++ language question was. Perhaps
next time you could be a bit more on topic.

Victor


Chris Mantoulidis写道:
Chris Mantoulidis wrote:
必须有一些提示,使程序更快。

我想这里超过50%的人会说避免if- S" ;.是的,我知道这会使程序更快,但有时会使如果更快是不可避免的,不是吗?

有什么方法可以让程序更快?

TIA,
cmad
There must be some tips to make a program quicker.

I guess more than 50% of ppl here will say "avoid the if-s". Yeah I
know this makes a program quicker but some times an "if" is
inevitable, isn''t it?

What are some tips to make a program quicker?

TIA,
cmad




正如其他人所说:

1.除非绝对必要,否则不要优化。

2.选择更有效的算法。

3.删除不必要的代码,数据和要求。

4.选择更有效的数据结构。

5.不要复制大块数据;使用指针。


至于if语句去,不用担心它们。

你可以结合一些if语句并使用逻辑运算符短路

。将布尔代数应用于

if语句以减少它们。但是,总是

努力提高程序的可读性。


删除if的唯一优势声明是

来提供连续执行并减少重新加载

的指令缓存。有些处理器有一个

指令缓存。处理

分支指令时会重新加载这些缓存。重新加载

缓存是一个昂贵的主张。但是,在大多数情况下,

的速度增益可以忽略不计。

只关注具有实时要求或

大数据处理的程序应该关注关于

这个问题。在大多数情况下,等待一块硬件或用户输入将从缓存优化中吸收任何

增益。这有点像

快速到达停车标志或交通

信号。


-

Thomas Matthews


C ++新闻组欢迎辞:
http://www.slack.net/~shiva/welcome.txt

C ++常见问题: http://www.parashift.com/c++-faq-lite

C常见问题: http://www.eskimo。 com /~scs / c-faq / top.html

alt.comp.lang.learn.c-c ++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html

其他网站:
http://www.josuttis.com - C ++ STL图书馆书



As others have said:
1. Don''t optimize unless absolutely necessary.
2. Choose more efficient algorithms.
3. Remove unnecessary code, data and requirements.
4. Choose more efficient data structures.
5. Don''t copy large blocks of data; use pointers.

As far as the "if" statements go, don''t worry about them.
You could combine some if statements and use short-circuiting
with the logical operators. Apply Boolean Algebra to your
if statements to reduce them down. However, always
strive for readability in your programs.

The only advantage to removing "if" statements is
to provide continuous execution and reduce reloading
of an instruction cache. Some processors have an
instruction cache. These caches get reloaded when
branch instructions are processed. Reloading the
cache is an expensive proposition. However, the
speed gain is negligible in most circumstances.
Only programs that have real-time requirements or
large data processing should be concerned about
this issue. For the most part, waiting for a
piece of hardware or user input will absorb any
gain from cache optimization. It''s kind of like
driving fast to reach a stop sign or traffic
signal.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book


这篇关于使程序更快捷的提示......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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