local variable vs pointer performance
<p>For the below code example, the speed to execute method "increment" by the pointer - num_ptr is significantly slower than the local variable - num. I think it is related to the virtual method, but I don't understand why. Please help explain this. I am trying to understand the performance issue from this example.</p>

<pre><code>#include &lt;iostream&gt;

const long long iterations_count = 1000000;

// a number interface
struct number {        
    virtual void increment() = 0;
};

struct concrete_number:number
{
    long long a;
    concrete_number(long long p){
        a = p;
    }
    void increment()
    {
        a+=1;
    }
};

int main() {

    concrete_number num(0);
    concrete_number* num_ptr = &amp;num;

    for (long long i = 0; i &lt; iterations_count; i++) {
        num.increment();
    }

    for (long long i = 0; i &lt; iterations_count; i++) {
        num_ptr-&gt;increment();
    }
    std::getchar();
}
</code></pre>
