c++ - Trying to avoid parameter overhead in function calls -


In a display critical application I am writing, at one point I repeatedly have the same function in a tight loop with millions Calling the bar always with the same parameter I decided to try to avoid the upper part of the parameter by putting parameters in a square. For example, first:

  some_class p1; Some_class p2; Some_class p3; For (integer number = 12345678; count; - number) af (p1, p2, p3); After   

:

  class foo // Private / public ignore for short [some_class & amp; p1_; some_class & amp; p2_; some_class & amp; p3_; Fu (some squares and p1, some squares and p2, some squares and p3): p1_ (p1), p2_ (p2), p3_ (p3_) {} zero executed (); } Some_class p1; Some_class p2; Some_class p3; Af F (P1, P2, P3); For (int calculation = 12345678; count; -cout) f.execute ();   

My profiling results were: = 11121 ms before, after = 11416ms.

I was expecting an improvement in the performance because I had the parameter address on the stack, but in return there was a slight decline.

Why would that happen? I am using Visual C ++ 2008 Express Edition, but I am thinking that there can be a stage anecdotal answer in it.

To completely avoid the function, some execute_loop (some_class and p1 , some_class & amp; p2, some_class and p3, const int iterations) (Number of iterations as an additional parameter) Create loop inside the function.


Some additional logic (all potentially automated by compiler from first optimization level, but hey):

  1. Business class for less logic in your strategy The member comes with a lack of respect. Your mileage may vary.

  2. If the function is not modified within the function, then declare them in the function signature to const , this indicates that the compiler that functions arguments Can run again without reading again.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -