#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <ctime>
#include <windows.h>
struct Object { void test() const{} };
struct bar {
void operator()(const Object& o) {
o.test();
}
};
struct foo {
__int64 start, end, freq;
HANDLE hprocess;
DWORD oldclass;
foo() : hprocess(GetCurrentProcess()), oldclass(GetPriorityClass(hprocess)) {
Sleep(10);
SetPriorityClass(hprocess, REALTIME_PRIORITY_CLASS);
QueryPerformanceFrequency((LARGE_INTEGER*)&freq);
QueryPerformanceCounter((LARGE_INTEGER*)&start);
}
~foo() {
QueryPerformanceCounter((LARGE_INTEGER*)&end);
SetPriorityClass(hprocess, oldclass);
std::cout << (int)(end - start) << std::endl;
}
};
const int N = 5000000;
int main()
{
Object a[N];
std::vector<Object> b(N);
{
std::cout << "test1 : ";
foo f;
for (int i = 0; i < N; ++i)
a[i].test();
}
{
std::cout << "test2 : ";
foo f;
for (std::size_t i = 0, n = b.size(); i < n; ++i)
b[i].test();
}
{
std::cout << "test3 : ";
foo f;
for (std::vector<Object>::const_iterator it = b.begin(), end = b.end(); it != end; ++it)
it->test();
}
{
std::cout << "test4 : ";
foo f;
std::for_each(b.begin(), b.end(), bar());
}
}