#include <Core/Core.h>

using namespace Upp;

inline void WaitInp() { static int tmp; scanf("%d", &tmp); }

typedef unsigned char U8;
typedef unsigned short U16;
typedef unsigned int U32;

template <class T> T AnyVal(const T& t) { return t; }
template <> U8 AnyVal(const U8& t) { return 123; }
template <> U16 AnyVal(const U16& t) { return 1234; }
template <> U32 AnyVal(const U32& t) { return 12345; }

template <class T>
DWORD bench(int sz, int rep, const T& t)
{
	static DWORD tBegin, tEnd;
	tBegin = GetTickCount();
	for (int ii = 0; ii < rep; ++ii)
	{
		T val = AnyVal(t);
		T* pt = new T[sz], *pi;
		
		pi = pt;
		for (int i = 0; i < sz; ++i, ++pi)
			*pi = val;
		pi = pt;
		for (int i = 0; i < sz; ++i, ++pi)
			val = *pi;
		
		delete [] pt;
	}
	tEnd = GetTickCount();
	return tEnd - tBegin;
}

CONSOLE_APP_MAIN
{
	U8 vu8; U16 vu16; U32 vu32;
	DWORD ba8, ba16, ba32;
	
	int testsize = 64;
	int testiter = 10000000;
	
	for (int i = 0; i < 14; ++i)
	{
		Cout() << "Size: " << testsize << "; Iterations: " << testiter << ";  ";
		ba8 = bench(testsize, testiter, vu8);
		ba16 = bench(testsize, testiter, vu16);
		ba32 = bench(testsize, testiter, vu32);
		Cout() << "8: " << ba8 << "; 16: " << ba16 << "; 32: " << ba32 << ";\n";
		testsize *= 2; testiter *= 0.5;
	}
	
	WaitInp();
}

