使用移位操作代替'a * b'
同上。
[i]但我个人认为,除非是在一个非常大的循环内,性能非常重要,而且你很清楚你自己在做什么,方可使用这种方法。否则提高性能所带来的程序晚读性的降低将是不合算的。
例子:
public class SMUL {
public void calculate(int a) {int mul = a * 4; // should be replaced with "a << 2".int mul2 = 8 * a; // should be replaced with "a << 3".int temp = a * 3;
}
}
更正:
package OPT;
public class SMUL {
public void calculate(int a) {int mul = a << 2; int mul2 = a << 3; int temp = a * 3; // 不能转换
}
}
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态