关于Andorid's FloatMath和Java's Math函数

在Android API 8的版本之前,如果不需要double精度,而float精度就可以满足需要,那么可以使用Android API 中提供的FloatMath函数代替Java中的Math函数,优化速度。

Android最新提示:如果只需要在Android API 8以及以上版本使用APP的话,可以直接是用Java提供的Math函数,因为最新的JIT已经对Math函数做了优化,除了占用内存double比float更多以外,使用Java's Math函数更快。

下面是Android官方最新的关于使用浮点型的性能提示

Avoid Using Floating-Point


As a rule of thumb, floating-point is about 2x slower than integer on Android-powered devices.

In speed terms, there's no difference between float and double on the more modern hardware. Space-wise,double is 2x larger. As with desktop machines, assuming space isn't an issue, you should prefer double to float.

Also, even for integers, some processors have hardware multiply but lack hardware divide. In such cases, integer division and modulus operations are performed in software—something to think about if you're designing a hash table or doing lots of math.


在Android API文档的FloatMath函数中,首句有提示
Math routines similar to those found in  Math . On versions of Android with a JIT, these are significantly slower than the equivalent  Math  functions, which should be used in preference to these.
这里的Math函数与Java中的Math函数类似。在带有JIT(Java即时编译器)的Android版本中(也就是Android API8及以上版本),这些方法要比Java中的相应的函数要慢很多,所以我们优先选择Java里面的Math函数。

当然,这要牺牲部分内存资源。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值