我是靠谱客的博主 疯狂盼望,这篇文章主要介绍double 和 float 性能差异测试,现在分享给大家,希望可以做个参考。

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

操作double大概是float的3倍的时间消耗。

 

public class DoubleFloatComparation {
    public static void main(String args[]) {    
     
     //double float comparation
     long start2 = System.nanoTime();
     float f = 0f;
     for(int i = 0; i< Integer.MAX_VALUE; i++){
      f += 0.1;
     }
     long end2 = System.nanoTime();
        System.out.println(end2 - start2);
     
        long start3 = System.nanoTime();
        double d = 0d;
        for(int i = 0; i< Integer.MAX_VALUE; i++){
         d += 0.1;
        }
        long end3 = System.nanoTime();
        System.out.println(end3 - start3);
        
    }
}

转载于:https://my.oschina.net/u/138995/blog/78879

最后

以上就是疯狂盼望最近收集整理的关于double 和 float 性能差异测试的全部内容,更多相关double内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(134)

评论列表共有 0 条评论

立即
投稿
返回
顶部