zuochunwei opened a new pull request #8193:
URL: https://github.com/apache/incubator-doris/pull/8193


   # Proposed changes
   i have tested final keyword's effect, the result shows
   1. call virtual member functions through derived class instance will more 
efficient if the function is marked as final, even if i use variable for 
switch, it's more efficient than virtual function vall
   2. tidy codes, some member data is not necessary, so i deleted it
   
   here is the test code:
   `
   uint64_t get_time()
   {
       timespec end;
       clock_gettime(CLOCK_MONOTONIC, &end);
       return (end.tv_sec) * 1000L * 1000L * 1000L + (end.tv_nsec);
   }
   
   class Base {
   public:
       Base() : type(0) {}
       virtual ~Base() {}
       virtual void f(int i) { ++x; }
       int x = 0;
       int type = 0;
   };
   
   int a[10]  = {1, 3, 4, 8, 9, 2, 6, 7, 5, 0};
   
   class Derived : public Base {
   public:
       Derived() { type = 1;}
       void f(int i) /*final*/ { j += a[i]; }
       int j = 0;
   };
   
   static void Test1() {
       uint64_t start = get_time();
       Derived* d = new Derived;
       Base* b = d;
       for (int x = 0; x < 1000; ++x)
       {
           for (int i = 0; i < 10; ++i)  b->f(i);
       }
       uint64_t end = get_time();
       std::cout << "j=" << d->j << " time:" << (end - start) << std::endl;
   }
   
   static void Test2() {
       uint64_t start = get_time();
       Derived* d = new Derived;
       for (int x = 0; x < 1000; ++x)
       {
           for (int i = 0; i < 10; ++i) d->f(i);
       }
       uint64_t end = get_time();
       std::cout << "j=" << d->j << " time:" << (end - start) << std::endl;
   }
   
   int main()
   {
       Test1();
       Test2();
       return 0;
   }
   `
   
   Issue Number: close #xxx
   
   ## Problem Summary:
   
   Describe the overview of changes.
   
   ## Checklist(Required)
   
   1. Does it affect the original behavior: (Yes/No/I Don't know)
   2. Has unit tests been added: (Yes/No/No Need)
   3. Has document been added or modified: (Yes/No/No Need)
   4. Does it need to update dependencies: (Yes/No)
   5. Are there any changes that cannot be rolled back: (Yes/No)
   
   ## Further comments
   
   If this is a relatively large or complex change, kick off the discussion at 
[d...@doris.apache.org](mailto:d...@doris.apache.org) by explaining why you 
chose the solution you did and what alternatives you considered, etc...
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to