双打比C#花车更快? [英] Are doubles faster than floats in c#?

查看:153
本文介绍了双打比C#花车更快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个应用程序,它读取的花车大数组,并与他们进行了一些简单的操作。我使用的花车,因为我认为这将会是增加了一倍快,但做一些研究后,我发现有关于这个话题有些混乱。谁能解释一下?

I'm writing an application which reads large arrays of floats and performs some simple operations with them. I'm using floats because I thought it'd be faster than doubles, but after doing some research I've found that there's some confusion about this topic. Can anyone elaborate on this?

推荐答案

简短的回答是,使用取其precision需要可接受的结果。

The short answer is, "use whichever precision is required for acceptable results."

您一保是业务上的浮点数据的前pression至少最高precision成员进行执行。所以相乘两个浮动的用至少的precision完成的浮动,然后乘以一个浮动将与至少增加一倍precision来完成。该标准规定,浮点]操作可以以更高precision比结果类型的操作执行。

Your one guarantee is that operations performed on floating point data are done in at least the highest precision member of the expression. So multiplying two float's is done with at least the precision of float, and multiplying a float and a double would be done with at least double precision. The standard states that "[floating-point] operations may be performed with higher precision than the result type of the operation."

由于面向.NET的JIT试图离开你的浮点运算中所要求的precision,大家可以看一看文档英特尔加快我们的业务。在Intel平台上的浮点运算可以在80bits的中间precision完成,并转换到所要求的precision。

Given that the JIT for .Net attempts to leave your floating point operations in the precision requested, we can take a look at documentation from Intel for speeding up our operations. On the Intel platform your floating point operations may be done in an intermediate precision of 80bits, and converted down to the precision requested.

从英特尔的指南,C ++浮点运算 1 (对不起,只有死树),他们提到:

From Intel's guide to C++ Floating-point Operations1 (sorry only have dead tree), they mention:


      
  • 除非需要通过双重或长双挣来的precision使用单个precision类型(例如,浮动)。更大precision类型增加存储器的大小和带宽要求。
      ...

  •   
  • 避免混合数据类型的算术EX pressions

  •   

这href=\"http://weblog.ikvm.net/PermaLink.aspx?guid=f300c4e1-15b0-45ed-b6a6-b5dc8fb8089e\">你可以慢下来自己不必要的强制类型最后一点是,从而导致JIT'd code这要求的x87投其80bit的中间格式之外的操作之间!

That last point is important as you can slow yourself down with unnecessary casts to/from float and double, which result in JIT'd code which requests the x87 to cast away from its 80bit intermediate format in between operations!

1。是的,它说,C ++,但CLR的C#标准以及知识让我们知道的信息,C ++应该适用于这种情况。

这篇关于双打比C#花车更快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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