2的指数的三种乘除运算方式速度测试
据说乘除2的指数用移位操作略快,自己测试一下
总的运算次数不太多:
都差不多
总的运算次数超级多:
单个运算:/=最快 >>=次之,差别比较明显,//最慢
连续运算:/和>>差不多快,//最慢,但是差别不太明显
;枫丹白露的小测试 a:=0x9999 c:=7777777 S := A_TickCount b:=0 loop,% c { b:=a*A_Index b>>=8 } T1:=b " >>=用时: " A_TickCount-S S := A_TickCount b:=0 loop,% c { b:=a*A_Index>>8 } T1.="`r`n"b " >>用时: " A_TickCount-S S := A_TickCount b:=0 loop,% c { b:=a*A_Index b:=b//256 } T2:=b " b//用时: " A_TickCount-S S := A_TickCount b:=0 loop,% c { b:=a*A_Index//256 } T2.="`r`n"b " b//用时2: " A_TickCount-S S := A_TickCount b:=0 loop,% c { b:=a*A_Index b/=256 } T3:=b " /=用时: " A_TickCount-S S := A_TickCount b:=0 loop,% c { b:=a*A_Index b//=256 } T3.="`r`n"b " //=用时: " A_TickCount-S MsgBox %c%次`r`n%T1%`r`n%T2%`r`n%T3%
厉害