Struct / Class Performance?

From: Bryan Parkoff (bryan.nospam.parkoff_at_nospam.com)
Date: 05/25/04


Date: Mon, 24 May 2004 22:09:29 +0000 (UTC)


    I have gathered time data for global variables, struct, and class. I
have shown the result that struct is faster than global variable. Second,
struct and class have the same speed while class is not bound to these
functions. Third, class is faster than struct while class is bound to these
functions.
    It is good, but inheritance is a big issue that it should be avoided.
If base class and derived class are bound through virtual or nonvirtual
inheritance, derived class must obtain a pointer from base class before it
can access variable and functions. It creates extra instructions per
variable and/or functions. It can be slow. If base class is only useful
while virtual / nonvirtual inheritance is disabled or removed, it creates
only less than two instructions per variable and/or functions. It can be
running much faster.
    I was done to read C++ source and disassembler code to compare. I did
find out that base class does not need extra instructions that it can save
hundred clock cycles. It would be best to create two or more base classes.
Copy variables from first base class to second base class without using
inheritance during the initialization before each base class can process
their own variables and/or functions that can be much faster.
    Do you agree? What about you (Matt Taylor)?

    I do see that data flat can be huge than stack flat that will be better
since stack flat should always be smaller that it is useful to push and pop
temporal variables only. All constant and nonconstant variables are always
modified in data flat inside struct or class. Is it true?

-- 
Bryan Parkoff


Relevant Pages

  • Re: Struct / Class Performance?
    ... > I have gathered time data for global variables, struct, and class. ... > inheritance, derived class must obtain a pointer from base class before it ... There is a big difference between inheritance and virtual functions. ...
    (comp.lang.asm.x86)
  • Re: Struct / Class Performance?
    ... > I have gathered time data for global variables, struct, and class. ... > inheritance, derived class must obtain a pointer from base class before it ...
    (comp.lang.asm.x86)
  • Re: template specialization
    ... >arguments that are pointers to a particular base class and not lose ... >Is there a way to specialize the template function so that my template ... your looking for SpecialEvent and classes derived from it. ... struct SpecialEvent ...
    (comp.lang.cpp)
  • Re: reference to pointer of derived class
    ... > struct Toyota: public Car{ ... working at a relatively low level of abstraction, ... In the base class it would be a NOP, ...
    (comp.lang.cpp)
  • Re: Empty base class (like Javas "interface")?
    ... > I tried defining it empty in the base class and with a non-empty ... except for the type of value they wrap, define a class template for such ... of utility classes like Dereferencer and Deleter below, ... struct Value: public Value_base ...
    (comp.lang.cpp)