Ask your own question, for FREE!
Mathematics 62 Online
OpenStudy (anonymous):

http://ideone.com/yfY2t How come the non-macro version of isort() is slower than the macro version of isort()?

OpenStudy (anonymous):

oh and I commented out the function version of isort() right above the macro

OpenStudy (anonymous):

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?

OpenStudy (anonymous):

I want to make my sorting functions as generic as possible,

OpenStudy (anonymous):

What does that mean?

OpenStudy (anonymous):

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

OpenStudy (anonymous):

although actually, it won't work for strings :-P

OpenStudy (anonymous):

Functions are ideal for such chunks of code. I won't use macros for anything but basic one expressions.

OpenStudy (anonymous):

what if the function is considerably slower than the macro :(

OpenStudy (anonymous):

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.

OpenStudy (anonymous):

so all I do is add the "inline" keyword to the isort() function and it will be alright?

OpenStudy (anonymous):

I think the isort() macro is almost as readable as the function anyway :-) all I added were backslashes :-P

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!