Sometimes we want to write our code in a normal way ,like multiple number multiplication. Usually we write it like this f = a * b * c * d * e; But in this way the complier will generate a lot of hidder temporaries for you. How to remove this temporaries but not giving up the old way, and at the same time to improve the performance. This way is crazy , but it is worth to do this sometimes. In this blog, I am going to show the difference of performance using two different way.
Shocking truth about the performance between default copy constructor and the one you defined. In this experiment ,we do it with two steps. first with the default or implicity copy constructor, the second one we use an explicit copy constructor;
This post is the following up of last post( using = rather than * ). In the last post, we implemented the operator function in a very normal way(define a temporary variable), some complier can optimize your code in this way, they call it Named Return Value Optimiztion. But some complier do not. we can not count on that. The only thing we can count on is the nameless return value optimiztion which is supported by almost all of the complier of C++. ```cpp
Suppose we defined a Class named V which overloaded the operator ,=, then which way is faster if you want to do a multiplication of V.
first way V c = a * b;
second way V c = a; c *= b;
Obviously the result is the same, but the thing we are curious is the performance. Let us do a experiment.
```cpp
Sometimes we can using C++ cool features to archive our goal of avoid unnecessary caculation, at the same time we don’t change the caller code at all. Like the example below, The GetLength function returns the square root of x, typically it is a very low efficient caculation.Sometimes it is not necessary to do this when do the comparsion. so when we use this GetLength to do a comparsion, we can using a series of C++ features to avoid it, the mainly features includes C++ Proxy object, Type Conversion Operator Overloading ,etc.