Calling a function has a performance penalty because you have to create variables, specify scope, pause the current variables and push data onto the call stack, just to name a few reasons.
C++ allows you to define an inline function, which should be short, to improve the performance. In doing so, the compiler will actually copy the code where the function is, instead of calling a function. This might make the executable a little larger, but also a little faster.
If you have something where timing is important, you can use an inline function.
To create an inline function, you create a function in the same manner you normally would, except you add inline to the front of the function header, like can be seen in this example:
inline int max(int x, int y)
{
int returnValue = y;
if( x > y )
{
returnValue = x;
}
return returnValue;
}
int main()
{
cout << max(3, 6) << endl;
}
Inline Functions in C++ was originally found on Access 2 Learn