I recently watched the << Reconstruction: Improving the Java in the existing code ... >> I wrote a test case, boasting "advanced features" such as Java reflection, I also write some test code to see. First of all, represent Performance data class:
class CapabilityCount {public: static void Out (); char * m_clue; CapabilityCount * m_pre; DWORD m_frequency; DWORD m_times; static CapabilityCount * head; CapabilityCount (char * clue);}; CapabilityCount * CapabilityCount :: head = 0;
CapabilityCount :: CapabilityCount (char * clue) {m_pre = head; head = this; m_clue = clue; / / Connect a piece, accept a string as output identifier.}
Void CapabilityCount :: out () // Output to text file {std :: fstream out; ctime time; out.open ("d: //testcount.txt", std :: ios_base :: Ate | std :: ios_base: : OUT; assert (out.is_open ()); time = ctime :: getCurrentTime (); out << "is beginning in" << Time.getDay () << ": << Time.GetHour () << ":" << Time.getminute () << "/ n"; CapabilityCount * pSearch = head;
While (pSearch) {OUT << "TYPE:" << pSearch-> m_clue << "all time (milliseconds):" << pSearch-> m_times << "be call frequency:" << pSearch-> m_frequency << "Average Time (MilliseConds):" << pSearch-> m_times / pSearch-> m_frequency << "/ n / n"; pSearch = pSearch-> m_pre;}
}
Then a "change person", responsible for updating the CapabilityCount class
Class CapabilityCountHelper {DWORD M_BEGINTIME; CapabilityCount & M_supervised; Public: CapabilityCountCountHelper (CapabilityCount & IN); ~ CapabilityCountHelper ();
}
CapabilityCountHelper :: CapabilityCount & IN: m_supervised (in) {m_begintime = gettickcount (); m_supervised.m_frequency; // is called the number}
CapabilityCountHelper :: ~ CapabilityCountHelper () {dWord spend = gettickcount () - m_begintime; m_supervised.m_times = spend; // Total time} How to use it? Before you want to test the function, add static capabilitycount // must There is static oh CapabilityCountInstance ("Function Name or else"); CapabilityCountHelper CapabilityCountHelperInstance (CapabilityCountInstance);
Too troublesome #define KILL_BILL__KILL_BILL__KILL_BILL (clue) static CapabilityCount / CapabilityCountInstance (clue);? / CapabilityCountHelper CapabilityCountHelperInstance (CapabilityCountInstance) /
I recently wanted to see << Kill Bill >>, although killing is not what I think :(
You can test with a more accurate time function. But this is not my business;
You can also add KILL_BILL_KILL_BILL__KILL_BILL ("CapabilityCount :: out") in the inner function or even the CapabilityCount :: OUT function; what happens, it is not my business :(
C programmer 9CBS really has a head! .. Wow, how to poured in the clothes !!! ???