四舍五入如何提高性能(如果有的话)? [英] How (if at all) could rounding Decimals improve performance?
问题描述
我很好奇,当我在Spark程序中对一堆小数进行任何形式的数学运算时,它对舍入数字有什么影响吗?例如:
I am curious when I am doing any sort of math on a a bunch of decimals in my Spark program does it make any difference to round numbers beforehand? For instance does:
3.000009481 * 10.90001001010
3.000009481 * 10.90001001010
计算与以下内容相同的时间:
Calculate the same time as something like:
3.000 * 10.900
3.000 * 10.900
在乘法,除法以及幂和平方根等更高级的内容上是否有所不同?
Does it differ for multiplication, division, and more advanced things like power and square root etc?
我想知道,因为当您对数百万个数字进行处理时,可以说它是毫秒级的整数吗?还是总是用小数点获得相同的计算时间?
I am wondering because lets say its a fraction of a millisecond when you are doing it on millions of numbers does it make sense to round? Or will you always get the same calculation times with decimals?
我有一个很大的aggregateByKey函数,正在执行大量计算.我所在的群集始终提供不一致的性能指标.
I have a large aggregateByKey function that is doing a lot of computation. The cluster I am on consistently provides inconsistent performance metrics.
推荐答案
It can make a huge difference numerically (see: What Every Computer Scientist Should Know About Floating-Point Arithmetic) but won't affect performance.
这篇关于四舍五入如何提高性能(如果有的话)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!