It is not known, it's a smile!

zhaozj2021-02-16  52

Don't send it, I know what happened, why can't I delete my own article? I think it should be

Abstract: I have always thought that VC6's implementation efficiency is very good. No matter how Microsoft's products, under the Windows platform, his efficiency should not be worse, are you discomfort? I have always thought that under VC6, the list of initialization will have certain performance improvement, theory, actually?

From an example of "Efficient C ", he gives the following example (slightly change): #include #include #include Using Namespace std;

Class Timer {public: Timer (): start (clock ()) {} ~ time () {cout << clock () - start << "ms" << endl;} private: clock_t start;

Class Person {public: Person (const char * s, const char * se) {name = s; sex = se;} private: string name, sex;};

INT main () {Timer * P = new Timer; for (int i = 0; i <1000000; i) Person P ("HUSTLI", "BOY"); delete P;

Return 0;} We call this version 1, according to our common sense, in the Person constructor, no initialization list, then constructing the Person object, will initialize Name and SEX 2 times, the efficiency will decline, and Should drop a lot! So we constructed version 2: Person (const char * s, const char * se): Name (s), SEX (SE) {} First, we will take the version 1 in VC6, Win2000 test ten times, take the average value, The results are as follows: 13949.0ms then, we use version 2 to test ten times in VC6, Win2000, take the average, the results are as follows: 14174.3ms This result, let me depress for a long time, I don't understand, I really don't understand, how Use the initial list, the efficiency is low? I think it may be related to the implementation of the String class, so I have the same test in DEV-C 4.9.5.0, the results are as follows: Version 1: 3186.5ms version 2: 3102.4ms first saw this As a result, I will hop: How is it better than VC6 speed? ! Conclusion: May DEV-C more in line with our expectations: Initialization lists can improve efficiency. String's default constructor consumes very small. Doubty: Why is the result of VC6 so abnormal? Why is the efficiency of VC6 so low? Looking forward to a master's answer.

转载请注明原文地址:https://www.9cbs.com/read-23865.html

New Post(0)