调用函数与内联代码的速度成本 [英] Speed cost of calling a function vs inline code

查看:75
本文介绍了调用函数与内联代码的速度成本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道一些关于功能的事情。


假设我需要经常在我的程序中交换两个整数。

这个因果方式将是声明

Hi, I want to know something about functions.

Say I need to swap two integers frequently in my program.
The ususal way will be to declare

展开 | 选择 | Wrap | < span class =codeLinkonclick =LineNumbers(this);>行号

推荐答案

您可以将函数声明为内联
You can declare the function as inline



我想知道一些关于函数的事情。


说我需要经常交换两个整数我的计划。

用户的方式是宣布

Hi, I want to know something about functions.

Say I need to swap two integers frequently in my program.
The ususal way will be to declare

展开 | 选择 | Wrap | 行号



但我确信使用函数比输入代码要慢我想要的地方。我想知道函数调用的成本。它会减慢多少程序?
But I am sure that using a function is slower than just typing the code where I want. I want to know how much a function call costs. by how much will it slow the program?



如果没有针对您的特定系统进行测量,很难判断,但它可能很重要,特别是对于很少次的小函数调用。

It is hard to tell without measuring it for your specific system, however it can be significant, especially for a small function call a lot of times.


这篇关于调用函数与内联代码的速度成本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆