// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <ctime>

using namespace std;

const int N = 20000000;

int main()
{
    int *ia = new int[N];
    clock_t ct1 = clock();
    for(int i = 0; i < N; i++)
    {
        ia[i] = i;
    }
    clock_t ct12 = clock();
    for(int i = 0; i < N; i++)
    {
        if(ia[i] != i)
        {
            cout << "Oops" << endl;
            exit(1);
        }
    }
    clock_t ct2 = clock();
    printf("%-15s %6.2f %6.2f\n", "integer array", (ct12 - ct1)/(double)CLOCKS_PER_SEC, (ct2 - ct12)/(double)CLOCKS_PER_SEC);
    vector<int> v;
    clock_t ct3 = clock();
    for(int i = 0; i < N; i++)
    {
        v.push_back(i);
    }
    clock_t ct34 = clock();
    for(int i = 0; i < N; i++)
    {
        if(v[i] != i)
        {
            cout << "Oops" << endl;
            exit(1);
        }
    }
    clock_t ct4 = clock();
    printf("%-15s %6.2f %6.2f\n", "vector", (ct34 - ct3)/(double)CLOCKS_PER_SEC, (ct4 - ct34)/(double)CLOCKS_PER_SEC);
    return 0;
}
