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 + "秒。");
           }
          }
          上面的代碼執行了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 + "秒。");
           }

          }
          上面的代碼執行了7秒
          第一段代碼構造了大約2的31次放的Long 實例

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


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


          網站導航:
           
          <2011年7月>
          262728293012
          3456789
          10111213141516
          17181920212223
          24252627282930
          31123456

          導航

          統計

          常用鏈接

          留言簿

          隨筆檔案

          新聞分類

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 滕州市| 蒙城县| 宝坻区| 鄢陵县| 宣化县| 手游| 綦江县| 隆昌县| 连江县| 波密县| 准格尔旗| 荣昌县| 湛江市| 武山县| 威海市| 大庆市| 固始县| 阜阳市| 饶河县| 富裕县| 留坝县| 太白县| 竹溪县| 门头沟区| 大埔区| 株洲县| 襄垣县| 措美县| 峡江县| 高邮市| 青河县| 怀宁县| 乌鲁木齐市| 吐鲁番市| 永胜县| 镇沅| 盖州市| 含山县| 吉安市| 七台河市| 孙吴县|