const int max_loop_set = 100000; const int loop_set = 10000; const int for_loop = 500; const int array_set = max_loop_set / loop_set; class test_cl { public: test_cl() { for (int i : value) i = 0; } void add() { for (int i : value) i += 1; } int value[array_set]; }; using CLL = test_cl[loop_set]; using PCLL = test_cl * [loop_set]; void func1() { CLL cll; for (int i = 0; i < loop_set; ++i) cll[i] = test_cl(); ULONGLONG tck = 0; for (int i = 0; i < 10; ++i) { ULONGLONG t1 = GetTickCount64(); for (int j = 0; j < for_loop; ++j) { for (auto cl : cll) cl.add(); } ULONGLONG t2 = GetTickCount64(); tck += (t2 - t1); } std::cout << "stack " << array_set << " - " << tck / 10 << std::endl; } void func2() { PCLL pll; for (int i = 0; i < loop_set; ++i) pll[i] = new test_cl; ULONGLONG tck = 0; for (int i = 0; i < 10; ++i) { ULONGLONG t1 = GetTickCount64(); for (int i = 0; i < for_loop; ++i) { for (auto pl : pll) pl->add(); } ULONGLONG t2 = GetTickCount64(); tck += (t2 - t1); } std::cout << "heap " << array_set << " - " << tck / 10 << std::endl; } int main() { func1(); func2(); return 0; }