尽可能小 [英] as small as possible

查看:77
本文介绍了尽可能小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




作为我的一个项目,我必须做一些C编程,实际上并不是真正的问题。它本身的问题是我将不得不尽可能快地编写一些代码




是否有任何gidelines对于这种事情?我怎么知道我的代码是否是
可能是我能为某个算法写的最小和最快的?并且

我在哪里可以找到这样的指导方针???


非常感谢提前


Arne Demmers

Hi,

As a project of mine I have to do some C programming, which in fact isn''t
the real problem. The problem it self is that I will have to write some code
that is as minimal as possible, and as fast as possible.

Are there any gidelines for this kind of thing? How do I know if my code is
possibly the smallest and fastest I could write for a certain algo?? And
where can I find thise kind of guidelines???

Many thanks in advance

Arne Demmers

推荐答案

2006年1月17日星期二12:01:15 +0100,在comp.lang.c中,Arne Demmers

< ar ********** @ scarlet.be>写道:
On Tue, 17 Jan 2006 12:01:15 +0100, in comp.lang.c , "Arne Demmers"
<ar**********@scarlet.be> wrote:
我怎么知道我的代码是否可能是我能为某个算法编写的最小和最快的代码?


没有办法知道这一点。这里是做什么


1)尽可能简单明了地编写算法代码。不要试图将b $ b优于编译器,它可以比你更好地优化。


2)测试它,确保它有效。没有必要优化破碎的

算法。


3)检查性能是否符合您的要求。你可能有一些实际要求要比较,如果没有,请回到你的老板

并要求一些。


4)然后才开始尝试优化。在这个阶段,你

可能需要成为一名专家程序员,并学习装配

语言。

我在哪里可以找到这种类型指南???
How do I know if my code is
possibly the smallest and fastest I could write for a certain algo??
There''s no way to know this. Here''s what to do

1) code the algo as simply and clearly as you can. DO NOT try to
outsmart the compiler, it can optimise much better than you can.

2) test it, make sure it works. No point optimizing a broken
algorithm.

3) check performance matches your requirements. You presumably have
some actual requirements to compare to, if not, go back to your boss
and ask for some.

4) then and only then, start trying to optimise. At this stage, you
may need to become an expert programmer, and to learn assembly
language.
And where can I find thise kind of guidelines???




优化规则:

规则1:不要这样做。

规则2(仅限专家):暂时不要这样做。

- MA Jackson


我们应该忘记小的效率,比如说大约97%的时间:

过早优化是所有邪恶的根源。

- Donald Knuth


" ;更多的计算罪是以效率的名义承诺的(没有

必然达到它)比任何其他单一原因 - 包括

盲目愚蠢。

- WA Wulf


马克麦金太尔

-


---- ==发表通过Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News == ----
http: //www.ne wsfeeds.com 世界排名第一的新闻组服务! 120,000多个新闻组

---- =东海岸和西海岸服务器农场 - 通过加密的总隐私= ----



Rules of Optimization:
Rule 1: Don''t do it.
Rule 2 (for experts only): Don''t do it yet.
- M.A. Jackson

"We should forget about small efficiencies, say about 97% of the time:
premature optimization is the root of all evil."
- Donald Knuth

"More computing sins are committed in the name of efficiency (without
necessarily achieving it) than for any other single reason - including
blind stupidity."
- W.A. Wulf

Mark McIntyre
--

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----


4)然后才开始尝试优化。在这个阶段,你可能需要成为一名专家程序员,并学习汇编语言。
4) then and only then, start trying to optimise. At this stage, you
may need to become an expert programmer, and to learn assembly
language.




所以你指的是使用C嵌入汇编程序代码来实现

尽可能优化它,比如


__asm {

一些说明(更少)比C编译器生成但是做同样的事情

的事情)

}


或者你是否意味着其他的东西?


感谢您的回答


Arne Demmers



So the thing your pointing at is working with in C embedde assembler code to
get it as optimal as possible, like

__asm{
some instructions (less than the C compiler had generated but does the same
thing)
}

or are you meaning sometrhing else?

thanks for your answer

Arne Demmers


Arne Demmers< ar ** ********@scarlet.be>写道:
Arne Demmers <ar**********@scarlet.be> wrote:
作为我的一个项目,我必须做一些C编程,这实际上并不是真正的问题。它本身的问题是我必须编写一些尽可能少的代码,并尽可能快。


我的第一个问题是:*为什么*你想优化?你是

真的确定它是necassery吗?

这种东西是否有任何gidelines?我怎么知道我的代码是否可能是我能为某个算法编写的最小和最快的代码?


优化时尺寸和速度往往是矛盾的目标,所以你需要在这里做出选择和优惠。


我不知道有可能计算算法的最小或禁止的实现。优化的第一条规则总是:

措施!在实际测量之前不要优化任何东西

值得优化。


1.设计你的算法。使用已知的快速算法来设计它。 (了解O()表示法等)

2.测试你的代码并确保它是100%正确

3.问问自己这是非常好的优化

4.测量代码花费大部分时间的时间

5.优化*仅*这段代码

6。回到第2步

我在哪里可以找到这种指导方针???
As a project of mine I have to do some C programming, which in fact isn''t
the real problem. The problem it self is that I will have to write some code
that is as minimal as possible, and as fast as possible.
My first question would be : *why* do you want to optimize ? Are you
really sure it is necassery ?
Are there any gidelines for this kind of thing? How do I know if my code is
possibly the smallest and fastest I could write for a certain algo ??
Size and speed are often contradictionary goals when optimizing, so you
will have to make choices and concessions here.

I do not know it it is possible to calculate the smallest or fasted
implementation of an algorithm. The first rule for optimizing is always:
measure! Do not optimize anything before you have actually measured it
is worth optimizing.

1. Design your algorithm. Design it with algorithms that are known to be
fast. (learn about O() notation etc)
2. Test your code and make sure it is 100% correct
3. Ask yourself it is really necassery to optimize
4. Measure where the code is spending the most of it''s time
5. Optimize *only* this piece of code
6. Go back to step 2
And where can I find thise kind of guidelines???




Richard Heathfield的书''C Unleashed''有一个关于

优化的好章节。

-

:wq

^ X ^ Cy ^ K ^ X ^ C ^ C ^ C ^ C



Richard Heathfield''s book ''C Unleashed'' has a good chapter about
optimizing.
--
:wq
^X^Cy^K^X^C^C^C^C


这篇关于尽可能小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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