Witam
Chciałem sobie porównać czas przypisania 10 milionów elementów w zwykły sposób do tablicy i za pomocą smart pointera. Niestety coś w tym kodzie jest nie tak, mimo że wydaje mi się, że powinien działać. Czy ktoś wie co tu jest nie tak i czy takie porównanie w ogóle jest prawidłowe?
#include "stdafx.h"
#include <iostream>
#include <time.h>
#include <cstdlib>
#include <memory>
using namespace std;
typedef unsigned long uLong;
float main()
{
const uLong howMany = 10000000;
clock_t start, stop;
double time_;
uLong arr[howMany];
start = clock();
for (size_t i = 0; i < howMany; ++i)
{
arr[i] = i;
arr[i] += 50;
}
stop = clock();
time_ = (double)(stop - start) / CLOCKS_PER_SEC;
cout << "Time without smart pointer: " << time_ << " s\n";
unique_ptr<uLong[]> ptr(new uLong[howMany]);
start = clock();
for (size_t i = 0; i < howMany; ++i)
{
ptr[i] = i;
ptr[i] += 50;
}
stop = clock();
time_ = (double)(stop - start) / CLOCKS_PER_SEC;
cout << "Time with smart pointer: " << time_ << " s";
cin.get();
return 4;
}
Dostaje taki komunikat: