Long 和long 性能的差別

          public class PerformanceTest {
           
          public static void main(String[] args){
               
          long time1 = System.currentTimeMillis();
               Long sum
          =0L;
               
          for(long i=0;i<Integer.MAX_VALUE;i++){
                   sum
          +=i;
               }
               System.out.println(sum);
               
          long time2 = System.currentTimeMillis();
               System.out.println((time2 
          - time1)/1000 + "秒。");
           }
          }
          上面的代碼執(zhí)行了28秒
          public class PerformanceTest {
           
          public static void main(String[] args){
               
          long time1 = System.currentTimeMillis();
               
          long sum=0L;
               
          for(long i=0;i<Integer.MAX_VALUE;i++){
                   sum
          +=i;
               }
               System.out.println(sum);
               
          long time2 = System.currentTimeMillis();
               System.out.println((time2 
          - time1)/1000 + "秒。");
           }

          }
          上面的代碼執(zhí)行了7秒
          第一段代碼構(gòu)造了大約2的31次放的Long 實例

          posted on 2011-07-13 16:11 鍵盤動物 閱讀(463) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          <2011年7月>
          262728293012
          3456789
          10111213141516
          17181920212223
          24252627282930
          31123456

          導(dǎo)航

          統(tǒng)計

          常用鏈接

          留言簿

          隨筆檔案

          新聞分類

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 东港市| 荃湾区| 永登县| 广西| 东港市| 丰原市| 屏山县| 兰西县| 龙海市| 贡嘎县| 武城县| 稻城县| 吴忠市| 海城市| 灌南县| 砀山县| 邛崃市| 邵东县| 郧西县| 县级市| 玛纳斯县| 扶风县| 安塞县| 沐川县| 乐清市| 特克斯县| 盐源县| 肇东市| 顺义区| 远安县| 东丽区| 永新县| 甘南县| 临猗县| 类乌齐县| 泗阳县| 古丈县| 拉萨市| 淮安市| 乐安县| 泸水县|