/* Lecture Code 2.3
 *
 * Time trial of the STL stack<string> vs. the CS106 Stack<string>.
 */

#include "genlib.h"
#include "stack.h"
#include <iostream>
#include <stack>
#include <ctime>
using namespace std;

const int NUM_ELEMS = 10000;
const int NUM_TESTS = 500;

/* If you're uncomfortable with template syntax, the next line simply
   indicates that the next function is generic and will accept any
   variable type.  However, the way it's written, the type must support
   functions called "push" and "pop."
 */
template <typename StackType>
	void RunTest()
{
	
	/* The timer works by using the C runtime library clock function,
	   which returns the current value of the CPU clock.  For more
	   information, consult a reference.
	*/
	clock_t start = clock();
	StackType myStack;

	for(int h = 0; h < NUM_TESTS; h++)
	{
		for(int i = 0; i < NUM_ELEMS; i++)
			myStack.push("Hello!");
		for(int h = 0; h < NUM_ELEMS; h++)
			myStack.pop();
	}

	start = clock() - start;

	cout << "Test completed in ";
	cout << ((double)(start) / CLOCKS_PER_SEC);
	cout << " seconds." << endl;
}

int main()
{
	/* This next syntax is a bit cryptic, but it basically says
	   to first run the test on the CS106 Stack and then to run
	   it on the STL stack.
	*/
	RunTest<Stack<string> >();
	RunTest<stack<string> >();

	return 0;
}