当前位置:网站首页>【函数的效率】
【函数的效率】
2022-07-17 05:08:00 【学会放下ta】
函数的效率
1、用宏定义来替换一些简单的函数以提高效率
很明显,这不行,宏定义坑太多,例如上次讲到的运算符优先级问题,就算加了括号还有其他问题,例如如果你是循环迭代调用
#define SQUARE(x) ((x)*(x))
...
int i=0;
while(i<=100)
{
printf("%d\n",SQUARE(i++));//自己试试打印出来是啥,为什么?
}
2、可以使用内联函数提高效率
直接在函数前面加inline,编译的时候函数代码会直接镶嵌到main函数中,不会调用堆栈提高了效率,相当于把函数变为了宏定义,拥有了其的优点,避免了宏的缺点,现在的编译器能自动将一些适合的变为内联函数,如果全部为内联函数则会延长编译过程。
边栏推荐
- 使用Flink SQL传输市场数据1:传输VWAP
- Common interview questions of operating system
- Redis source code analysis dynamic string implementation (SDS)
- The first smart contract program faucet sol
- Rk356x u-boot Institute (command section) 3.4 usage of MEM memory related commands
- BUUCTF 杂项——二维码
- OpenDDS的QoS和自定义QoS(校时TimingQosPolicy)
- Round robin schedule problem
- Redis source code analysis 3 implementation of discontinuous traversal
- 2.6.2 memory leakage
猜你喜欢
随机推荐
基于PaddleOCR解决文本检测训练模型与inference模型预测效果不一致的问题
BUUCTF 杂项——二维码
Solve the problem of inconsistent prediction effect between text detection training model and information model based on paddleocr
从20s优化到500ms,我用了这三招
Get the multi-functional version of the maximum and minimum values of the internal values of the objects in the array and the full version of the roll call system, and show the effect
Log4j的使用
[ES6] quickly print user information to the page
js 原生对象加属性
2020-10-22
MySQL cache strategy and solution
The latest news of spring recruitment in 2022: the average salary of it Internet industry is 18500 yuan
Pat class B 1017: a divided by B
线程池如何监控,才能帮助开发者快速定位线上错误?
2.6.2 memory leakage
Swagger configuration and use
(elaborate) ES6 remaining parameters, ES6 built-in objects, template string content (detailed example Dictionary) and practical cases of flexible use of the project
markdown笔记以及Typora相关快捷键
Solutions for vscode terminal failure
mysql的锁
UML(用例图,类图,对象图,包图)