I am having a slight performance issue with inline function. Consider the following code:-
inline int left(int x) {
return 2*x;
}
inline int right(int x) {
return 2*x+1;
}
main() {
for(int i=0;i<200000000;i++) {
int L=left(i);
int R=right(i);
}
}
This when compiled and executed (with and without -finline-function flag) takes around 1.90 secs on my computer. However when I replace the inline functions with macros it takes just 1.26 secs. Although its highly unlikely that a function will be executed 200 million times but still I would like to know if there anyway to achieve that kind to performance using inline functions ?
EDIT: After receiving a couple of offensive comments I realised I wasn't very clear with my question. I just wanted to know how to achieve the same performance without using any optimisation flags. Ofcourse its more sensible to simply use -O2 or -O3, I just wanted to learn.