#include <iostream>
#include <vector>
#include <chrono>
#include <cstring>
const int SIZE = 1024*1024;
void WithArray()
{
using namespace std;
char* a = new char[SIZE];
auto b = &a[0];
auto e = &a[SIZE];
memset(a, 0, SIZE);
int total=0;
auto begin = chrono::system_clock::now();
for(int c=0; c<100; c++) {
for(auto p=b; p<e;) {
total += *p++;
}
}
auto end = chrono::system_clock::now();
cout << total << ":" << chrono::duration_cast<chrono::milliseconds>(end-begin).count() << endl;
delete[] a;
}
void WithVector()
{
using namespace std;
vector<char> a(SIZE);
auto b = a.begin();
auto e = a.end();
int total=0;
auto begin = chrono::system_clock::now();
for(int c=0; c<100; c++) {
for(auto it=b; it<e;) {
total += *it++;
}
}
auto end = chrono::system_clock::now();
cout << total << ":" << chrono::duration_cast<chrono::milliseconds>(end-begin).count() << endl;
}
int main()
{
WithArray();
WithVector();
WithArray();
WithVector();
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8Y2hyb25vPgojaW5jbHVkZSA8Y3N0cmluZz4KCmNvbnN0IGludCBTSVpFID0gMTAyNCoxMDI0OwoKdm9pZCBXaXRoQXJyYXkoKQp7Cgl1c2luZyBuYW1lc3BhY2Ugc3RkOwoJY2hhciogYSA9IG5ldyBjaGFyW1NJWkVdOwoJYXV0byBiID0gJmFbMF07CglhdXRvIGUgPSAmYVtTSVpFXTsKCgltZW1zZXQoYSwgMCwgU0laRSk7CglpbnQgdG90YWw9MDsKCQoJYXV0byBiZWdpbiA9IGNocm9ubzo6c3lzdGVtX2Nsb2NrOjpub3coKTsKCWZvcihpbnQgYz0wOyBjPDEwMDsgYysrKSB7CgkJZm9yKGF1dG8gcD1iOyBwPGU7KSB7CgkJCXRvdGFsICs9ICpwKys7CgkJfQoJfQoJYXV0byBlbmQgID0gY2hyb25vOjpzeXN0ZW1fY2xvY2s6Om5vdygpOwoJY291dCA8PCB0b3RhbCA8PCAiOiIgPDwgY2hyb25vOjpkdXJhdGlvbl9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