http://ideone.com/yfY2t How come the non-macro version of isort() is slower than the macro version of isort()?
oh and I commented out the function version of isort() right above the macro
Making a function call is slightly more expensive because of overhead involved in pushing stuff on to the stack and retrieving that after returning from function call. Any case, why would use a macro for such an elaborate piece of code?
I want to make my sorting functions as generic as possible,
What does that mean?
so it won't matter whatever type array I pass to it. All I need to do to make my isort() work on an array of doubles or even strings is to just pass the appropriate compare() function
although actually, it won't work for strings :-P
Functions are ideal for such chunks of code. I won't use macros for anything but basic one expressions.
what if the function is considerably slower than the macro :(
It should be marginally slower, but that is not a big deal. In that case, why even have a macro rather than "inline" code that does exactly the same thing. At least, it is more readable.
so all I do is add the "inline" keyword to the isort() function and it will be alright?
I think the isort() macro is almost as readable as the function anyway :-) all I added were backslashes :-P
Join our real-time social learning platform and learn together with your friends!