/* Lecture Code 2.5
 *
 * Time trial of vector vs deque for the push_front (or insert(container.begin())) functions.
 * Refer to 2.2 or 2.3 for more info on tricky syntax.
 */

#include <iostream>
#include <vector>
#include <deque>
#include <ctime>
using namespace std;

const int NUM_ELEMS = 10000;
const int NUM_TESTS = 100;

void RunVectorTest()
{
	
	clock_t start = clock();
	vector<int> myContainer;

	for(int h = 0; h < NUM_TESTS; h++)
	{
		for(int i = 0; i < NUM_ELEMS; i++)
			myContainer.insert(myContainer.begin(), i);
		for(int h = 0; h < NUM_ELEMS; h++)
			myContainer.erase(myContainer.begin());
	}

	start = clock() - start;

	cout << "Vector finished in ";
	cout << ((double)(start) / CLOCKS_PER_SEC);
	cout << " seconds." << endl;
}

void RunDequeTest()
{
	
	clock_t start = clock();
	deque<int> myContainer;

	for(int h = 0; h < NUM_TESTS; h++)
	{
		for(int i = 0; i < NUM_ELEMS; i++)
			myContainer.push_front(i);
		for(int h = 0; h < NUM_ELEMS; h++)
			myContainer.pop_front();
	}

	start = clock() - start;

	cout << "Deque finished in ";
	cout << ((double)(start) / CLOCKS_PER_SEC);
	cout << " seconds." << endl;
}

int main()
{
	RunVectorTest();
	RunDequeTest();

	return 0;
}