c++ 优化效率

1。 int max(int a,int b)    vs  int max(const int &a,const int &b) 后者的效率要高,因为不需要拷贝一次a,b
2。 全局变量int a【100】vs  static int a【100】, 后者效率要高.  我在arm上对数组的访问进行测试,用于存储一些乘法结果。如果不加static 反而效率不如直接使用乘法。猜测:此处的效率应该和不同位置的缓存的命中效率有关。

猜你喜欢

转载自blog.csdn.net/a302792317/article/details/81114069