void TestOneDataStructure(DataStructureTester<T>& tester, string data_structure_name, int test_number) { cout << data_structure_name << "," << tester.DoSequentialAdd(0, ADD_REMOVE_FIND_OPERATIONS, 1) << "," << test_number << ",sequential add" << endl; cout << data_structure_name << "," << tester.DoRandomAdd(ADD_REMOVE_FIND_OPERATIONS) << "," << test_number << ",random add" << endl; cout << data_structure_name << "," << tester.DoSequentialFind(0, ADD_REMOVE_FIND_OPERATIONS, 1) << "," << test_number << ",sequential find" << endl; cout << data_structure_name << "," << tester.DoSequentialRemove(0, ADD_REMOVE_FIND_OPERATIONS, 1) << "," << test_number << ",sequential remove" << endl; cout << data_structure_name << "," << tester.DoRandomFind(ADD_REMOVE_FIND_OPERATIONS) << "," << test_number << ",random find" << endl; cout << data_structure_name << "," << tester.DoRandomRemove(ADD_REMOVE_FIND_OPERATIONS) << "," << test_number << ",random remove" << endl; }
int main() { DataStructureTester<BinarySearchTree<BSTNode1<int>,int> > test; DataStructureTester<ChainedHashTable<int> > test2; DataStructureTester<LinearHashTable<int> > test3; DataStructureTester<RedBlackTree<RedBlackNode1<int>,int> > test4; int store1 = 0, store2 = 0, store3 = 0, store4 = 0, store5 = 0, store6 = 0; for(int i = 0; i<20; i++){ store1 += test.DoSequentialAdd(1,50000,1); store2 += test.DoRandomAdd(50000); store3 += test.DoSequentialFind(1,50000,1); store4 += test.DoRandomFind(50000); store5 += test.DoSequentialRemove(1,50000,1); store6 += test.DoRandomRemove(50000); } cout<<"Average Time Binary Search Tree Sequential Add: "<<store1/20<<" Seconds"<<endl; cout<<"Average Time Binary Search Tree Random Add: "<<store2/20<<" Seconds"<<endl; cout<<"Average Time Binary Search Tree Sequential Find: "<<store3/20<<" Seconds"<<endl; cout<<"Average Time Binary Search Tree Random Find: "<<store4/20<<" Seconds"<<endl; cout<<"Average Time Binary Search Tree Sequential Remove: "<<store5/20<<" Seconds"<<endl; cout<<"Average Time Binary Search Tree Random Remove: "<<store6/20<<" Seconds"<<endl<<endl; store1 = 0; store2 = 0; store3 = 0; store4 = 0; store5 = 0; store6 = 0; for(int i = 0; i<20; i++){ store1 += test2.DoSequentialAdd(1,50000,1); store2 += test2.DoRandomAdd(50000); store3 += test2.DoSequentialFind(1,50000,1); store4 += test2.DoRandomFind(50000); store5 += test2.DoSequentialRemove(1,50000,1); store6 += test2.DoRandomRemove(50000); } cout<<"Average Time Chained Hash Table Sequential Add: "<<store1/20<<" Seconds"<<endl; cout<<"Average Time Chained Hash Table Random Add: "<<store2/20<<" Seconds"<<endl; cout<<"Average Time Chained Hash Table Sequential Find: "<<store3/20<<" Seconds"<<endl; cout<<"Average Time Chained Hash Table Random Find: "<<store4/20<<" Seconds"<<endl; cout<<"Average Time Chained Hash Table Sequential Remove: "<<store5/20<<" Seconds"<<endl; cout<<"Average Time Chained Hash Table Random Remove: "<<store6/20<<" Seconds"<<endl<<endl; store1 = 0; store2 = 0; store3 = 0; store4 = 0; store5 = 0; store6 = 0; for(int i = 0; i<20; i++){ store1 += test3.DoSequentialAdd(1,50000,1); store2 += test3.DoRandomAdd(50000); store3 += test3.DoSequentialFind(1,50000,1); store4 += test3.DoRandomFind(50000); store5 += test3.DoSequentialRemove(1,50000,1); store6 += test3.DoRandomRemove(50000); } cout<<"Average Time Linear Hash Table Sequential Add: "<<store1/20<<" Seconds"<<endl; cout<<"Average Time Linear Hash Table Random Add: "<<store2/20<<" Seconds"<<endl; cout<<"Average Time Linear Hash Table Sequential Find: "<<store3/20<<" Seconds"<<endl; cout<<"Average Time Linear Hash Table Random Find: "<<store4/20<<" Seconds"<<endl; cout<<"Average Time Linear Hash Table Sequential Remove: "<<store5/20<<" Seconds"<<endl; cout<<"Average Time Linear Hash Table Random Remove: "<<store6/20<<" Seconds"<<endl<<endl; store1 = 0; store2 = 0; store3 = 0; store4 = 0; store5 = 0; store6 = 0; for(int i = 0; i<20; i++){ store1 += test4.DoSequentialAdd(1,50000,1); store2 += test4.DoRandomAdd(50000); store3 += test4.DoSequentialFind(1,50000,1); store4 += test4.DoRandomFind(50000); store5 += test4.DoSequentialRemove(1,50000,1); store6 += test4.DoRandomRemove(50000); } cout<<"Average Time Red Black Tree Sequential Add: "<<store1/20<<" Seconds"<<endl; cout<<"Average Time Red Black Tree Random Add: "<<store2/20<<" Seconds"<<endl; cout<<"Average Time Red Black Tree Sequential Find: "<<store3/20<<" Seconds"<<endl; cout<<"Average Time Red Black Tree Random Find: "<<store4/20<<" Seconds"<<endl; cout<<"Average Time Red Black Tree Sequential Remove: "<<store5/20<<" Seconds"<<endl; cout<<"Average Time Red Black Tree Random Remove: "<<store6/20<<" Seconds"<<endl<<endl; cout<<"END"<<endl; return 0; }
int main() { DataStructureTester<BinarySearchTree<BSTNode1<int>, int> > test; DataStructureTester<RedBlackTree<RedBlackNode1<int>, int> > test2; DataStructureTester<LinearHashTable<int> > test3; DataStructureTester<ChainedHashTable<int> > test4; //These are holders for the sums of the total number of milliseconds for each test float t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0; //BStree test //Runs each test 20 times and sums up the times for (int i = 0; i < 20; i++) { t1 = t1 + test.DoSequentialAdd(0, 50000, 1); t2 = t2 + test.DoRandomAdd(50000); t3 = t3 + test.DoSequentialFind(0, 50000, 1); t4 = t3 + test.DoRandomFind(50000); t5 = t5 + test.DoSequentialRemove(0, 50000, 1); t6 = t6 + test.DoRandomRemove(50000); } //Prints out the averages of each test then resets the holders cout << t1 / 20 << endl; cout << t2 / 20 << endl; cout << t3 / 20 << endl; cout << t4 / 20 << endl; cout << t5 / 20 << endl; cout << t6 / 20 << "\n" << endl; t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0; //RBtree test for (int i = 0; i < 20; i++) { t1 = t1 + test2.DoSequentialAdd(0, 50000, 1); t2 = t2 + test2.DoRandomAdd(50000); t3 = t3 + test2.DoSequentialFind(0, 50000, 1); t4 = t3 + test2.DoRandomFind(50000); t5 = t5 + test2.DoSequentialRemove(0, 50000, 1); t6 = t6 + test2.DoRandomRemove(50000); } cout << t1 / 20 << endl; cout << t2 / 20 << endl; cout << t3 / 20 << endl; cout << t4 / 20 << endl; cout << t5 / 20 << endl; cout << t6 / 20 << "\n" << endl; t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0; //LHashTable test for (int i = 0; i < 20; i++) { t1 = t1 + test3.DoSequentialAdd(0, 50000, 1); t2 = t2 + test3.DoRandomAdd(50000); t3 = t3 + test3.DoSequentialFind(0, 50000, 1); t4 = t3 + test3.DoRandomFind(50000); t5 = t5 + test3.DoSequentialRemove(0, 50000, 1); t6 = t6 + test3.DoRandomRemove(50000); } cout << t1 / 20 << endl; cout << t2 / 20 << endl; cout << t3 / 20 << endl; cout << t4 / 20 << endl; cout << t5 / 20 << endl; cout << t6 / 20 << "\n" << endl; t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0; //CHashTable test for (int i = 0; i < 20; i++) { t1 = t1 + test4.DoSequentialAdd(0, 50000, 1); t2 = t2 + test4.DoRandomAdd(50000); t3 = t3 + test4.DoSequentialFind(0, 50000, 1); t4 = t3 + test4.DoRandomFind(50000); t5 = t5 + test4.DoSequentialRemove(0, 50000, 1); t6 = t6 + test4.DoRandomRemove(50000); } cout << t1 / 20 << endl; cout << t2 / 20 << endl; cout << t3 / 20 << endl; cout << t4 / 20 << endl; cout << t5 / 20 << endl; cout << t6 / 20 << "\n" << endl; return 0; }