#include <iostream>
#include <vector>
const int size = 50000000;
std::vector<int> test1()
{
return std::vector<int>(size);
}
void test2(std::vector<int>& v)
{
v.assign(size, 0);
}
int main()
{
std::vector<int> v(size);
clock_t c1, c2, c3, c4, c5, c6;
// コピー
c1 = clock();
v = static_cast<const std::vector<int>&>(test1());
c2 = clock();
// ムーブ
c3 = clock();
v = test1();
c4 = clock();
// バッファの再利用
c5 = clock();
test2(v);
c6 = clock();
printf("コピー : %d\n", static_cast<int>(c2 - c1));
printf("ムーブ : %d\n", static_cast<int>(c4 - c3));
printf("再利用 : %d\n", static_cast<int>(c6 - c5));
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgoKY29uc3QgaW50IHNpemUgPSA1MDAwMDAwMDsKCnN0ZDo6dmVjdG9yPGludD4gdGVzdDEoKQp7CiAgICByZXR1cm4gc3RkOjp2ZWN0b3I8aW50PihzaXplKTsKfQoKdm9pZCB0ZXN0MihzdGQ6OnZlY3RvcjxpbnQ+JiB2KQp7CiAgICB2LmFzc2lnbihzaXplLCAwKTsKfQoKaW50IG1haW4oKQp7CiAgICBzdGQ6OnZlY3RvcjxpbnQ+IHYoc2l6ZSk7CiAgICBjbG9ja190IGMxLCBjMiwgYzMsIGM0LCBjNSwgYzY7CgogICAgLy8g44Kz44OU44O8CiAgICBjMSA9IGNsb2NrKCk7CiAgICB2ID0gc3RhdGljX2Nhc3Q8Y29uc3Qgc3RkOjp2ZWN0b3I8aW50PiY+KHRlc3QxKCkpOwogICAgYzIgPSBjbG9jaygpOwoKICAgIC8vIOODoOODvOODlgogICAgYzMgPSBjbG9jaygpOwogICAgdiA9IHRlc3QxKCk7CiAgICBjNCA9IGNsb2NrKCk7CgogICAgLy8g44OQ44OD44OV44Kh44Gu5YaN5Yip55SoCiAgICBjNSA9IGNsb2NrKCk7CiAgICB0ZXN0Mih2KTsKICAgIGM2ID0gY2xvY2soKTsKCiAgICBwcmludGYoIuOCs+ODlOODvCA6ICVkXG4iLCBzdGF0aWNfY2FzdDxpbnQ+KGMyIC0gYzEpKTsKICAgIHByaW50Zigi44Og44O844OWIDogJWRcbiIsIHN0YXRpY19jYXN0PGludD4oYzQgLSBjMykpOwogICAgcHJpbnRmKCLlho3liKnnlKggOiAlZFxuIiwgc3RhdGljX2Nhc3Q8aW50PihjNiAtIGM1KSk7Cn0K