Recently read, feel C + + two points to compare the impact of efficiency
1, is the construction and destruction of temporary objects. In order to avoid the creation of temporary objects, C + + compiler has done a lot of optimizations. such as the initialization list of the object's constructors, and the NRV optimization,
2, Class TCLASS3, {4, Public:5, Tclass (): Temp ("") 6, {7, 8,}9, 10, String temp;11,};
When you use the initialization list, the compiler avoids the creation of a temporary object when the constructor is generated. Without initializing the table, the compiler generates constructors as follows:
Class Tclass{public:tclass ():d ata ("") { String temp = ""; data = temp;} string data;};
NRV optimization refers to the optimizations that the compiler makes to code when the object is returned as a function value, before the compiler optimizes the code
void Fun () { string temp; temp = Test ();} String Test () {string temp; return temp}
This is done after the optimization:
12, void Fun () 13, {14, string temp;15, temp = Test (), 16,}17, void Test (string& temp) 18, {19, 20, return; 21,}
The premise of NRV optimization is that the object needs to provide a copy constructor to activate the NRV optimization in the compiler when the copy constructor is provided
There is also a virtual function caused by the dynamic binding, virtual function of the formation of the polymorphic mechanism, so that the program only in the run time to determine the specific function is called, this will also affect the efficiency of some degree.
About the efficiency of C + +