English 中文(简体)
浮动速度要慢于一倍吗? 有64个轨道方案运行速度快于32个轨道方案?
原标题:Is float slower than double? Does 64 bit program run faster than 32 bit program?

采用<代码>float 低于<条码>的类型

我听到,现代英特尔公司和AMD CPU能够以比浮动更快的两倍计算。

标准数学功能是什么(sqrt,pow,,sin,cos等)? 采用单一计算法的计算应大大加快,因为它需要较少的浮动点操作。 例如,单一精确度<代码>sqrt 可使用简单的数学公式,而不是双重精确度sqrt。 此外,我听说,64个轨道模式(在64个比值非洲顾问办公室编制和运行时)的标准数学功能较快。 有什么确切答案?

最佳回答

传统的X86结构利用浮动点单位进行浮动点计算。 邮联在其内部登记册中进行所有计算,每个登记册的精度为80比方。 每当你尝试使用<代码>float或double时,这些变量首先从记忆中填入万国邮联的内部登记册。 这意味着实际计算速度绝对没有变化,因为无论如何计算都是全方位进行的。 唯一可能不同的是,从记忆中提取价值的速度加快,并将结果重新储存到记忆中。 自然,在32个轨道平台上,与<代码>float相比,负荷/储存时间可能更长。 在64个轨道平台上,斜线没有任何区别。

Modern x86 architectures support extended instruction sets (SSE/SSE2) with new instructions that can perform the very same floating-point calculations without involving the "old" FPU instructions. However, again, I wouldn t expect to see any difference in calculation speed for float and double. And since these modern platforms are 64-bit ones, the load/store speed is supposed to be the same as well.

在不同的硬件平台上,情况可能有所不同。 但是,通常较小的浮动点类型不应提供任何性能效益。 较小的浮动点类型的主要目的是节省记忆,而不是改进业绩。

Edit: (To address @MSalters comment) What I said above applies to fundamental arithmetical operations. When it comes to library functions, the answer will depend on several implementation details. If the platform s floating-point instruction set contains an instruction that implements the functionality of the given library function, then what I said above will normally apply to that function as well (that would normally include functions like sin, cos, sqrt). For other functions, whose functionality is not immediately supported in the FP instruction set, the situation might prove to be significantly different. It is quite possible that float versions of such functions can be implemented more efficiently than their double versions.

问题回答

你的第一个问题已经回答:here on SO

您的第二个问题完全取决于你所处理数据的“大小”。 它 all倒了该系统的低水平结构及其如何处理大价值。 32个轨道系统中64个参数的数据需要2个周期才能进入2个登记册。 关于64个轨道系统的同样数据只能需要1个周期才能进入1个登记册。

一切都取决于你重新做什么。 我认为,没有快速而艰难的规则,因此,你需要分析目前的任务,选择最适合你对具体任务的需求。

从一些研究和经验衡量 我在 Java做了以下工作:

  • basic arithmetic operations on doubles and floats essentially perform identically on Intel hardware, with the exception of division;
  • on the other hand, on the Cortex-A8 as used in the iPhone 4 and iPad, even "basic" arithmetic on doubles takes around twice as long as on floats (a register FP addition on a float taking around 4ns vs a register FP on a double taking around 9ns);
  • I ve made some timings of methods on java.util.Math (trigonometrical functions etc) which may be of interest -- in principle, some of these may well be faster on floats as fewer terms would be required to calculate to the precision of a float; on the other hand, many of these end up being "not as bad as you d think";

在某些情况下,例如,记忆带宽问题超过了“粗”计算时间,这也是事实。

虽然在大多数系统中,<代码>double<>/code>将与各个数值的<编码>float相同,但你还是认为,像<代码>sqrt、sin等电子计算功能在单一计算中应当比计算其双重计算要快得多。 在C99,即使您的变量为double<>/code>,也可使用sinf等功能。

所提到的另一个问题是记忆(和同样的储存装置)带宽。 如果你们有数百万或数十亿的价值观,float将几乎肯定是double<>/code”的两倍,因为所有东西都是有记忆的或有的。 在某些情况下,使用<代码>float <>/code>作为阵列或拆卸储存的类型,是一个很好的理由,但我认为,在你进行计算时,使用<代码>float<>/code>的变量并不是一个很好的理由。

在x86 FPU中,“native”内部浮动点为80比特。 这与<代码>float(32 bits)和double<>code(64 bits)不同。 每次在万国邮联内部或之外进行价值转移时,都会进行换算。 只有一个联邦调查局指示,负责sin的操作,并在内部代表80位。

Whether this conversion is faster for float or for double depends on many factors, and must be measured for a given application.

它取决于加工商。 如果加工商有本土的双重计算指示,其计算速度通常要快于只做双倍计算一次,将其改为双倍,重复计算,然后将其改为浮动。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...