各种C操作的表现 [英] The performance of all kinds of C operations

查看:74
本文介绍了各种C操作的表现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




有谁知道任何描述各种C操作(相对)

性能的链接?例如:与乘法相比,加和b $ b的速度有多快。在一台典型的机器上。


谢谢!


-

BY

Hi,

Does anyone know of any link which describes the (relative)
performance of all kinds of C operations? e.g: how fast is "add"
comparing with "multiplication" on a typical machine.

Thanks!

--
B. Y.

推荐答案

mrby写道:
mrby wrote:


有谁知道任何描述的链接(相对)
各种C操作的表现?例如:与乘法相比,添加的速度有多快。在典型的机器上。
Hi,

Does anyone know of any link which describes the (relative)
performance of all kinds of C operations? e.g: how fast is "add"
comparing with "multiplication" on a typical machine.




包含这类信息的网页分散在网上。我见过的大多数都是高度系统特定的,无论他们是否说他们都是b $ b。我看到的一个页面做了相当多的努力来分配成本。对于各种C构造,但是它们似乎根植于优化者不那么激进的时代,而且当CPU和内存之间的速度差异不是那么大时......

巨大。


现在问一个

加法是否比乘法更慢或更快几乎毫无意义,即使

指定数据类型。如果加法的操作数在内存中是
而乘法的操作数在寄存器中,则
乘法可能会更快地完成。分区

可能会更快完成;即使采用

a寄存器驻留值的平方根也可能比执行

更快,这会产生两个内存引用。


你可以通过忽略

内存,多级缓存和流水线的效果来获得答案 -

但你忽略了答案现实不太可能是非常有用的。这就像是注意到喷气式飞机比自行车更快了b / b
因此选择了一架1英里

旅程的飞机。


除了微小且不断减少的一小部分案例之外,微观优化是浪费时间和精力的。选择一个好的

算法而不用担心它是否使用乘法

或加法,指针算术或数组索引。然后尽可能清晰而有力地编码

。除非和

之前再去吧,直到你测量了最终的表现并发现它不足够。


-

Eric Sosman
es ***** @ acm-dot-org.inva lid



Pages with this sort of information are scattered about
the Web. Most that I''ve seen have been highly system-specific,
whether they say they are or not. One page I saw made a fairly
serious effort to assign "costs" to various C constructs, but
it seemed rooted in the days when optimizers were less radical
and when the speed disparity between CPU and memory was not so
enormous.

Nowadays it is very nearly meaningless to ask whether an
addition is slower or faster than a multiplication, even if the
data types are specified. If the operands of the addition are
in memory while those of the multiplication are in registers,
the multiplication will likely finish far sooner. A division
will likely finish far sooner; even taking the square root of
a register-resident value will likely be quicker than performing
an addition that incurs two memory references.

You can probably get an answer by ignoring the effects of
memory, of the multiple levels of cache, and of pipelining --
but the answer you get by ignoring reality is not likely to be
very helpful. It''s like noticing that jet airplanes are faster
than bicycles, and therefore choosing an airplane for a one-mile
journey.

In all but a tiny and steadily diminishing fraction of cases,
micro-optimization is a waste of time and effort. Choose a good
algorithm without worrying about whether it uses multiplications
or additions, pointer arithmetic or array indexing. Then code it
as clearly and robustly as you can. Go no further unless and
until you have measured the resulting performance and found it
inadequate.

--
Eric Sosman
es*****@acm-dot-org.invalid


mrby写道:
有没有人知道任何描述各种(相对)
性能的链接C操作?例如:与乘法相比,添加的速度有多快。在一台典型的机器上。
Does anyone know of any link which describes the (relative)
performance of all kinds of C operations? e.g: how fast is "add"
comparing with "multiplication" on a typical machine.




嗯,事情并不那么简单,但我有一个这样的旧页

的信息仍然站起来:

http:// www。 pobox.com/~qed/optimize.html


其中我说过:算术运算性能已经订购

大致由:transcendental函数,平方根,模数,除法,

乘以,加2次幂/减去/多次除以

2 /模2的幂次幂。 ;我想我应该添加额外的,

结尾的减法和逻辑运算。无论如何,这个列表是

在几乎所有架构上仍然很大。所有架构似乎在这些操作上表现如此相似的原因是

构建逻辑的最佳或接近最好的技术

所有这些硬件操作通常都是众所周知的。这是值得注意的

现实。


但是,应该注意的是,随着时间的推移,内存带宽还没有保留
与现代CPU速度保持同步。正因为如此,即使因为trascendental函数现在不再慢于第一次

时间未缓存的内存访问,操作也很慢。因此,如果您将内存访问视为

操作,这将是一个主要的一个随着时间的推移改变其相对性能(通过变慢) 。


-

Paul Hsieh
http://www.pobox.com/~qed/
http://bstring.sf.net/



Well, things are not that simple, but I have an old page with this kind
of information that still stands up:

http://www.pobox.com/~qed/optimize.html

where I stated that: "Arithmetic operation performance is ordered
roughly by: transcendental functions, square root, modulo, divide,
multiply, add/subtract/mutiply by power of 2/divide by power of
2/modulo by power of 2." I guess I should have added addition,
subtraction and logic operations at the end. Anyhow, this list is
still largely true on pretty much all architectures. The reason why
all architectures seem to perform so similarly on these operations is
that the best or near best techniques for building logic that perform
all those operations in hardware are generally well known. This is a
reality worth noting.

However, it should be noted that over time, memory bandwidth has not
kept pace with modern CPU speeds. Because of this, operations even as
slow as trascendental functions are now no longer slower than first
time uncached memory accesses. So if you think of memory access as an
"operation", this would be the one major one which has changed its
relative performance over time (by getting slower).

--
Paul Hsieh
http://www.pobox.com/~qed/
http://bstring.sf.net/


2006年4月29日05:55:30 - 0700,mrby <双****** @ gmail.com>写在

comp.lang.c:
On 29 Apr 2006 05:55:30 -0700, "mrby" <bi******@gmail.com> wrote in
comp.lang.c:


有谁知道描述(亲属)的任何链接
各种C操作的表现?例如:与乘法相比,添加的速度有多快。在一台典型的机器上。

谢谢!
Hi,

Does anyone know of any link which describes the (relative)
performance of all kinds of C operations? e.g: how fast is "add"
comparing with "multiplication" on a typical machine.

Thanks!




你的问题毫无意义的真正原因是没有
$ b就C而言,$ b就像典型的机器这样的东西。这是
不仅仅是理论上的,8位
微控制器之间存在巨大差异,例如8051或AVR,以及64位
桌面处理器,如奔腾或PowerPC,另一方面。


这些天我做了很多工作,使用DSP进行倍增和

另外花费相同的时间,一个时钟周期。并且

它也可以在一个时钟周期内做MAC,将两个数相乘并将它们加到

累加器中。或者它可以将数字平方并在一个时钟周期内将它加到累加器中。


-

杰克Klein

主页: http://JK-Technology.Com



comp.lang.c的常见问题解答 http://c-faq.com/

comp.lang.c ++ http://www.parashift.com/c++-faq-lite/

alt.comp.lang.learn.c-c ++
http:// www。 contrib.andrew.cmu.edu/~a...FAQ-acllc.html



The real reason that your question is meaningless is that there is no
such thing as a "typical machine", as far as C is concerned. This is
not just theoretical, there is a vast difference between 8-bit
microcontrollers such as an 8051 or AVR on the one hand, and 64-bit
desk top processors like Pentium or PowerPC on the other.

I do a lot of work these days with a DSP where multiplication and
addition take exactly the same amount of time, one clock cycle. And
it can also do MAC, multiply two numbers and add them to an
accumulator, in one clock cycle. Or it can square a number and add it
to an accumulator, all in one clock cycle.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html


这篇关于各种C操作的表现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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