#include <iostream>
#include <cstdlib>
#include <ctime>
#include <unistd.h>
#include <boost/chrono.hpp>
#include "row.hpp"

using namespace std;

double random_double() {
	return -10000.0 + (double)rand() / RAND_MAX*20000.0;
}

void test(int n) {
	double* b=new double[n];

	for (int i=0;i<n;i++) {
		b[i]=random_double();
	}

	boost::chrono::high_resolution_clock::time_point start;
	boost::chrono::high_resolution_clock::time_point stop;
	boost::chrono::microseconds ms;

	//Quick Sort
	{
	row<double> r(b,n);
	start=boost::chrono::high_resolution_clock::now();
	quick_sort(r);
	stop=boost::chrono::high_resolution_clock::now();
	ms=boost::chrono::duration_cast<boost::chrono::microseconds>(stop-start);
	cout << "Quick sort: \t\t" <<ms.count() << "us" <<endl;
	}

	sleep(0.5);

	//Bubble Sort
	{
	row<double> r(b,n);
	start=boost::chrono::high_resolution_clock::now();
	bubble_sort(r);
	stop=boost::chrono::high_resolution_clock::now();
	ms=boost::chrono::duration_cast<boost::chrono::microseconds>(stop-start);
	cout << "Bubble Sort: \t\t" <<ms.count() << "us" <<endl;
	}

	sleep(0.5);

	//Merge Sort
	{
	row<double> r(b,n);
	start=boost::chrono::high_resolution_clock::now();
	merge_sort(r);
	stop = boost::chrono::high_resolution_clock::now();
	ms=boost::chrono::duration_cast<boost::chrono::microseconds>(stop-start);
	cout << "Merge Sort: \t\t"<< ms.count() << "us" <<endl;
	}

	sleep(0.5);

	//Selection Sort
	{
	row<double> r(b,n);
	start=boost::chrono::high_resolution_clock::now();
	selection_sort(r);
	stop=boost::chrono::high_resolution_clock::now();
	ms=boost::chrono::duration_cast<boost::chrono::microseconds>(stop-start);
	cout << "Selection Sort: \t"<<ms.count() << "us" <<endl;
	}

	sleep(0.5);

	//Insertion Sort
	{
	row<double> r(b,n);
	start=boost::chrono::high_resolution_clock::now();
	insertion_sort(r);
	stop=boost::chrono::high_resolution_clock::now();
	ms=boost::chrono::duration_cast<boost::chrono::microseconds>(stop-start);
	cout<<"Insertion Sort: \t" << ms.count() << "us" <<endl;
	}

	sleep(0.5);

	//Enumeration sort
	{
	row<double> r(b,n);
	start=boost::chrono::high_resolution_clock::now();
	enumeration_sort(r);
	stop=boost::chrono::high_resolution_clock::now();
	ms=boost::chrono::duration_cast<boost::chrono::microseconds>(stop-start);
	cout <<"Enumeration Sort: \t" <<ms.count() <<"us"<<endl;
	}

	sleep(0.5);

	delete b;

}

int main() {
	srand((unsigned)time(NULL));
	cout <<"Test gia n=1000 random times sto [-10000,10000]: " <<endl;
	test(1000);
	cout << "Test gia n=10000 random times sto [-10000,10000]: " <<endl;
	test(10000);

	return 0;
}
