对乘法和加法进行基准测试 [英] Benchmarking multiplications and additions

查看:96
本文介绍了对乘法和加法进行基准测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要确定添加需要多长时间以及

乘法需要多长时间。到目前为止,我一直在尝试在我的程序中使用clock()

函数,以便了解CPU花费多长时间来计算它,唯一的问题是我得到相当不一致的

结果,不足以不知道两个代码之间的代码

运行得更快而不运行大约十次并使得平均值

报告的CPU时间。


现在我的主要问题是确定3个浮点数增加是否比一个更慢或更快浮点乘法。我尝试制作小的

程序循环一些添加或一些乘法试图找到

out,但不仅我仍然得到不一致的结果,我也不是

确定它是否正确(我不确定执行3 * 5大约一个b / bbb亿次是否相关)


那么如何可靠地确定我的CPU计算需要多长时间?
添加或乘法(甚至是其他操作)?

I need to determine how long does an addition take and how long does a
multiplication takes. So far I''ve been trying to use the clock()
function in my programs in order to find out how long it took the CPU
to compute it, the only problem is that I get fairly inconsistent
results, inconsistent enough not to know between two codes which code
runs faster without running each about ten times and making the average
of the reported CPU times.

Right now my main problem is to determine whether 3 float additions are
slower or faster than one float multiplication. I tried making small
programs looping some additions or some multiplications to try to find
out, but not only do I still get inconsistent results, I''m also not
sure if it is even right (i''m not sure that performing 3*5 about one
billion times is relevant)

So how do I determine reliably how long it takes for my CPU to compute
an addition or a multiplication (or even other opeartions)?

推荐答案

在文章< 11 ********************** @ z34g2000cwc.googlegroups .com> ;,

Michel Rouzic< Mi ******** @ yahoo.fr>写道:
In article <11**********************@z34g2000cwc.googlegroups .com>,
Michel Rouzic <Mi********@yahoo.fr> wrote:
我需要确定添加需要多长时间以及
乘法需要多长时间。


C语言标准没有规定

操作的时间,也没有关于测量这些时间的方法。因此,

comp.lang.c并不是讨论此类问题的最佳新闻组。


现在我的主要问题是确定是否有3个浮动加法比一次浮点乘法更慢或更快。我尝试制作小的
程序循环一些添加或一些乘法试图找出
,但不仅我仍然得到不一致的结果,我也不确定它是否是偶数对(我不确定执行3 * 5大约一亿次是否相关)
I need to determine how long does an addition take and how long does a
multiplication takes.
The C language standards have no specification about timings of
operations, nor about methods to measure those timings. Thus,
comp.lang.c is not the best newsgroup to discuss such matters in.

Right now my main problem is to determine whether 3 float additions are
slower or faster than one float multiplication. I tried making small
programs looping some additions or some multiplications to try to find
out, but not only do I still get inconsistent results, I''m also not
sure if it is even right (i''m not sure that performing 3*5 about one
billion times is relevant)




有很多因素可能会影响时机,

包括CPU正在处理的其他事项,包括

缓存效果和分支时序,以及(在某些CPU上)分支预测,
并包括编译器如何处理循环展开。


基准测试新闻组可能有助于编写更准确的测量代码。 br />
-

编程是在你忙于制定其他计划时发生的事情。



There are a lot of factors that could be affecting the timing,
including matters of what else the CPU is working on, and including
cache effects and branch timing, and (on some CPUs) branch prediction,
and including how your compiler handles loop unrolling.

A benchmarks newsgroup could likely be of assistance in writing
more accurate measuring code.
--
Programming is what happens while you''re busy making other plans.


Michel Rouzic认为:
Michel Rouzic opined:
我需要确定添加需要多长时间以及
多长时间乘法需要。到目前为止,我一直在尝试在我的程序中使用clock()函数,以便找出CPU计算它需要多长时间,唯一的问题是
我得到相当不一致的结果,不够稳定
不知道两个代码之间哪些代码运行得更快,而不是每次运行大约十次并且使得报告的CPU时间的平均值。


< snip>

那么如何可靠地确定我的CPU计算加法或乘法所花费的时间(或者甚至其他的
opeartions)?
I need to determine how long does an addition take and how
long does a multiplication takes. So far I''ve been trying to
use the clock() function in my programs in order to find out
how long it took the CPU to compute it, the only problem is
that I get fairly inconsistent results, inconsistent enough
not to know between two codes which code runs faster without
running each about ten times and making the average of the
reported CPU times.
<snip>
So how do I determine reliably how long it takes for my CPU to
compute an addition or a multiplication (or even other
opeartions)?




正如其他人所说的那样,这里不是主题。


Ever所以稍微回复是:`clock()`可能无法提供您需要的

粒度。使用

执行分析器可能要好得多。查询包含工具链的小组

和/或操作系统(例如Linux上提供的`gprof`)。


-

BR,弗拉基米尔


我们是蚁丘世界的蚁人。

- Ray Bradbury



As was noted by others, this is off topic here.

Ever so slightly reply is: `clock()` may not provide the
granularity you require. It is probably much better to use
execution profiler. Inquire in group covering your tool chain
and/or OS for a good one (e.g. `gprof` is available on Linux).

--
BR, Vladimir

We are anthill men upon an anthill world.
-- Ray Bradbury


Michel Rouzic写道:
Michel Rouzic wrote:
我需要确定添加需要多长时间以及
乘法需要多长时间。到目前为止,我一直在尝试在我的程序中使用clock()
函数,以便了解CPU计算它需要多长时间,唯一的问题是我得到了相当的不一致
结果,不一致,不知道两个代码之间的代码运行得更快,而不是每次运行大约十次,并使报告的CPU时间平均值。
I need to determine how long does an addition take and how long does a
multiplication takes. So far I''ve been trying to use the clock()
function in my programs in order to find out how long it took the CPU
to compute it, the only problem is that I get fairly inconsistent
results, inconsistent enough not to know between two codes which code
runs faster without running each about ten times and making the average
of the reported CPU times.




如果做一次这个测试的结果太不规则而无法得出结论,为什么不做一百万次和相反的时间呢?确保

取随机数,这样编译器就不会通过用常数值替换它来优化计算结果。


Remco



If the result of doing this test once is too irregular to draw conclusions
from, why not do it a million times and time that instead? Make sure to
take random numbers so the compiler it won''t optimise the computations out
by replacing it with a constant value.

Remco


这篇关于对乘法和加法进行基准测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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