1 Gprof
Practice
1. Time consumed for initializing large objects
The entire execution process is called 307 times, and the initialization time of the object accounts for 6.5%.
Before the program enters the constructor, the parent class Object of the class and all child member variable objects have been generated and constructed. It is a waste to assign values to constructors. If the constructor already knows how to initialize the sub-member variables of the class, you should assign the initialization information to the sub-member variables through the initialization list of the constructor, instead of performing the initialization in the constructor body. Because these sub-member variables have been initialized once before they enter the constructor. In the C ++ program, creating/destroying objects is a very prominent operation that affects performance. First, if an object is generated from the global heap, you must first perform the dynamic memory allocation operation. As we all know, dynamic allocation/recycling has always been very time-consuming in C/C ++ programs. Because it involves finding memory blocks with matching sizes, you may need to truncate them after finding them, and then you need to modify and maintain the linked list of global heap memory usage information.
2. Improper Map use
string Recordset::GetField(const string &strName){ int nIndex; if (hasIndex==false) { nIndex = m_nPos; } else { nIndex = m_vSort[m_nPos].m_iorder; } if (m_fields[strName]==0) { LOG_ERR("Recordset::GetField:"<<strName<<" Not Find!!"); } return m_records[nIndex].GetValue(m_fields[strName] - 1) ;}
string Recordset::GetField(const string &strName){ unordered_map::iterator iter = m_fields.find(strName); if (iter == m_fields.end()) { LOG_ERR("[Recordset::GetField] "<< strName <second - 1) ;}