
#include <iwear/stopwatch.h>
#include <iostream>
#include <iomanip>
#include "virt.h"

using namespace std;

int main ( void )
{
    volatile vbase* v = new vder;

    const uint32_t rounds = 300;
    const uint32_t calls = 500000;
    
    double min_b = 5.0;
    double min_v = 5.0; 
    iwear::StopWatch sw;
    for( volatile uint32_t j = 0; j < rounds; ++j )
    {
	sw.Start();
	for(volatile uint32_t i = 0; i <  calls; ++i )
	{
	    if( v->basefunc() != 0 );
	}
	sw.Stop();

	double base_time = sw.Time() / calls;
	min_b = min(min_b,base_time);

	sw.Start();
	for(volatile uint32_t i = 0; i <  calls; ++i )
	{
	    v->vfunc();
	    if( v->vfunc() != 0 );
	}
	sw.Stop();
	double v_time = sw.Time() / calls;
	min_v = min(min_v,v_time);

    }
    cout << std::setprecision(15);
    cout << "Base Call : " << min_b << endl;
    cout << "VPtr Call : " << min_v << endl;
    cout << "Factor    : " << min_v/min_b << endl;

}
