rangersly cf4b2cb324 FIX: merge gcc_g++ create shared lib
FIX: C in linux  read  KEY
    FIX: .bashrc  echo  DIR
    FIX: gcc_g++ create shared lib
2025-05-09 18:07:44 +08:00

15 lines
834 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# C++代码性能优化的方法
+ 使用const关键字
+ 避免频繁进行内存分配和释放
+ 尽量减少值传递,多用引用来传递参数
+ 局部变量VS静态变量多次调用可能局部更快
+ ++i和i++的效率问题(使用迭代器可能比使用指针更优:迭代器++i可以减少一次构造和析构
+ 避免使用多重继承
+ 低级代码使用位运算替代算术运算
+ 将小粒度函数声明为内联函数inline
+ 循环内定义,还是循环外定义对象:由构造函数和复制操作的效率比较决定
+ 小函数放在同一循环内效率高大函数分开放效率更高由cpu寄存器决定
+ 尽量少使用`dynamic_cast`
+ 减少除法运算的使用,除数尽量使用常量,让编译器优化
+ 多用直接初始化