#include <sys/time.h>
#include <string>
#include <iostream>
#include <cstdlib>
#include "LeakyStack.h"
#include "LeakyStackA.h"
#include "LeakyStackB.h"
using namespace std;

void usage() {
    cout << "Usage: TestEfficiency X N" << endl;
    cout << "       where X is either A or B, and N > 0" << endl;
}

int main(int argc, const char* argv[]) {

    LeakyStack* LS(NULL);

    if (argc != 3) {
	usage();
    } else {
	int N(-1);
	N = atoi(argv[2]);
	if (N < 1)
	    usage();
	else {
	    switch (argv[1][0])
		{
		case 'a':
		case 'A':
		    LS = new LeakyStackA(N);
		    break;
		case 'b':
		case 'B':
		    LS = new LeakyStackB(N);
		    break;

		default:
		    cout << "First argument must be A or B" << endl;
		    usage();
		}
	    if (LS) {
		timeval startTime, endTime;
		gettimeofday(&startTime, 0);
		for (int k=0; k < 5*N; k++)
		    LS->push("Testing");
		for (int k=0; k < N; k++)
		    LS->pop();
		gettimeofday(&endTime, 0);
		double elapsed =
		    float(endTime.tv_sec - startTime.tv_sec) +
		    float(endTime.tv_usec - startTime.tv_usec)/1000000;
		cout << "Elapsed Time (seconds): " << elapsed << endl;
	    }
	}
    }
}
