posts - 41,  comments - 40,  trackbacks - 0

          /*******************************************************************************
          ?*
          ?* 乘除法和等效的位運算
          ?*
          ?* 1024 = 2*2*2*2*2*2*2*2*2*2 = 100 0000 0000
          ?*
          ?******************************************************************************/
          class BitOperation
          {
          ? public static void main( String[] args )
          ? {
          ??? //被除數
          ??? long dividend=182495073L;

          ??? long temp=0L;

          ??? long begin=0L;


          ??? ////////////////////////////////////////////////////////////////////////////
          ??? //
          ??? // dividend/1024等效于dividend>>10
          ??? //
          ??? ////////////////////////////////////////////////////////////////////////////
          ??? begin=System.currentTimeMillis();

          ??? for( int i=0; i<10000000; i++ )
          ?????? {
          ???????? temp=dividend/1024;
          ?????? }

          ??? System.out.println( temp+" 總共耗時:"+( System.currentTimeMillis()-begin )+"毫秒" );

          ??? begin=System.currentTimeMillis();

          ??? for( int i=0; i<10000000; i++ )
          ?????? {
          ???????? temp=dividend>>10;
          ?????? }

          ??? System.out.println( temp+" 總共耗時:"+( System.currentTimeMillis()-begin )+"毫秒\r\n" );


          ??? ////////////////////////////////////////////////////////////////////////////
          ??? //
          ??? // dividend*1024等效于dividend<<10
          ??? //
          ??? ////////////////////////////////////////////////////////////////////////////
          ??? begin=System.currentTimeMillis();

          ??? for( int i=0; i<10000000; i++ )
          ?????? {
          ???????? temp=dividend*1024;
          ?????? }

          ??? System.out.println( temp+" 總共耗時:"+( System.currentTimeMillis()-begin )+"毫秒" );

          ??? begin=System.currentTimeMillis();

          ??? for( int i=0; i<10000000; i++ )
          ?????? {
          ???????? temp=dividend<<10;
          ?????? }

          ??? System.out.println( temp+" 總共耗時:"+( System.currentTimeMillis()-begin )+"毫秒\r\n" );


          ??? ////////////////////////////////////////////////////////////////////////////
          ??? //
          ??? // dividend%1024等效于dividend-( dividend>>10<<10 )
          ??? //
          ??? ////////////////////////////////////////////////////////////////////////////
          ??? begin=System.currentTimeMillis();

          ??? for( int i=0; i<10000000; i++ )
          ?????? {
          ???????? temp=dividend%1024;
          ?????? }

          ??? System.out.println( temp+" 總共耗時:"+( System.currentTimeMillis()-begin )+"毫秒" );

          ??? begin=System.currentTimeMillis();

          ??? for( int i=0; i<10000000; i++ )
          ?????? {
          ???????? temp=dividend-( dividend>>10<<10 );
          ?????? }

          ??? System.out.println( temp+" 總共耗時:"+( System.currentTimeMillis()-begin )+"毫秒\r\n" );
          ? }
          }

          posted on 2007-09-17 09:17 NeedJava 閱讀(3117) 評論(3)  編輯  收藏 所屬分類: Java
          主站蜘蛛池模板: 临沭县| 宣恩县| 巴彦县| 马尔康县| 原平市| 行唐县| 修水县| 姚安县| 抚顺县| 东丰县| 平舆县| 金乡县| 城口县| 鹤壁市| 栖霞市| 大石桥市| 乌兰浩特市| 邢台县| 喀喇| 新泰市| 芷江| 岳西县| 西贡区| 项城市| 威宁| 定陶县| 金昌市| 石柱| 乐安县| 得荣县| 平山县| 香河县| 扶沟县| 灵宝市| 老河口市| 象州县| 阳西县| 竹溪县| 平阴县| 武乡县| 保亭|