speed of the function call

Hey, I wanted to write some code with bit operations and didnt want to use <bitset> because i tested it with some bit operations and its turned to be slower than just using these operations on simple int or long long

Lets get to the question!
I created these 2 functios just for the readability of the code and I read that 1 guy told that function call dont affect speed much because compiler generates equal code to that if I didnt call function but used just full code instead. So here are my 2 funtions

1
2
3
4
inline void change_bit(long long& val, long long num, long long bitval)
{
	val = (val & ~(1 << num)) | (bitval << num);
}

1
2
3
4
template <class I, class I2, class B>
inline void change_bit_T(I& val, I2 num, B bitval){
	val = (val & ~(1 << num)) | (bitval << num);
}

Now when I tested them in for loop turned out that simple
val = (val & ~(1 << num)) | (bitval << num); worked 7 times faster than when I called any of these functions. Is that normal?
Last edited on
Did you turn on compiler optimization/release mode?
Thanks for answer man!
No I haven't, its all in default mode, I'm using VS 2013. Will have to check how to turn it on
That's probably it, can close this topic :) Thanks a lot!
Last edited on
Topic archived. No new replies allowed.