当前位置:网站首页>【函数的效率】
【函数的效率】
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函数中,不会调用堆栈提高了效率,相当于把函数变为了宏定义,拥有了其的优点,避免了宏的缺点,现在的编译器能自动将一些适合的变为内联函数,如果全部为内联函数则会延长编译过程。
边栏推荐
- 交换机用户模式、特权模式、全局模式、端口模式
- Distributed registry etcd
- 性能瓶颈查找-火焰图分析
- Cesium 获取鼠标点击处经纬度的三种方法
- mysql的缓存方案问题解决
- ambari2.7.5集成es6.4.2
- ArcMap creates a constant grid and tessellates it into a new grid
- JS native object plus attributes
- User mode protocol stack - UDP implementation based on netmap
- Markdown notes and related shortcut keys of typora
猜你喜欢

Nacos configuration management

Common interview questions of operating system

Parent components plus scoped sometimes affect child components

MySQL transactions

一次全面的性能优化,从5秒优化到1秒

mysql 缓存策略和解决方案

Redis source code analysis - data structure and Implementation (Dictionary dict)

Cesium BIND Mouse Events and remove Mouse Events

How to deal with the mismatch between subtitle files and video files

Excel计算本月剩余天数
随机推荐
Usage and examples of vlookup function
Nacos配置管理
Questions d'entrevue courantes du système d'exploitation
(elaborate) ES6 remaining parameters, ES6 built-in objects, template string content (detailed example Dictionary) and practical cases of flexible use of the project
Addition and removal of cesium geojson data
Flex弹性布局
Excel计算本月剩余天数
使用Flink SQL传输市场数据1:传输VWAP
Cesium 获取鼠标点击处经纬度的三种方法
交换机用户模式、特权模式、全局模式、端口模式
分布式存储-fastdfs
Excel导入长数据末尾变000
2.6.2 memory leakage
面渣逆袭:线程池夺命连环十八问,面试官直夸我
mysql的锁
[AI] action recognition using simple neural network -- Based on coco key points
redis 源码分析3 间断遍历的实现
基于PaddleOCR解决文本检测训练模型与inference模型预测效果不一致的问题
网络命令:网卡信息,netstat,arp
Excel imports long data and changes to 000 at the end