#include "linear_finder.h" #include "parallel_finder.h" #include "timer.h" #include "tree_finder.h" #include "word_list_generator.h" #include #include #include using std::string, std::string_view, std::vector, std::thread, std::cout, std::endl; vector generate_word_list() { cout << "\ngenerating word list" << endl; Timer generator_timer; auto word_list = WordListGenerator().generate(); generator_timer.stop(); cout << "word list generator took " << generator_timer << endl; cout << "word list is " << word_list.size() << " element(s) long" << endl; return word_list; } void test_linear_finder(const vector &word_list) { cout << "\nrunning linear finder" << endl; LinearFinder linear_finder(word_list); Timer find_timer; auto result = linear_finder.find_prefix("ABCD"); find_timer.stop(); cout << "linear finder took " << find_timer << endl; cout << "result list is " << std::distance(result.cbegin(), result.cend()) << " element(s) long" << endl; } void test_parallel_finder(const vector &word_list) { cout << "\nrunning parallel finder" << endl; const size_t thread_count = thread::hardware_concurrency(); cout << "using " << thread_count << " threads" << endl; ParallelFinder parallel_finder(word_list, thread_count); Timer find_timer; auto result = parallel_finder.find_prefix("ABCD"); find_timer.stop(); cout << "parallel finder took " << find_timer << endl; cout << "result list is " << std::distance(result.cbegin(), result.cend()) << " element(s) long" << endl; } void test_tree_finder(const vector &word_list) { cout << "\nrunning tree finder" << endl; Timer constructor_timer; TreeFinder tree_finder(word_list); constructor_timer.stop(); cout << "tree finder constructor took " << constructor_timer << endl; Timer find_timer; auto result = tree_finder.find_prefix("ABCD"); find_timer.stop(); cout << "tree finder took " << find_timer << endl; cout << "result list is " << std::distance(result.cbegin(), result.cend()) << " element(s) long" << endl; } int main(int argc, char *argv[]) { cout << "\n== VectorSearch ==" << endl; auto word_list = generate_word_list(); test_linear_finder(word_list); test_parallel_finder(word_list); test_tree_finder(word_list); return EXIT_SUCCESS; }