112 lines
3.2 KiB
C++
112 lines
3.2 KiB
C++
#include "grouped_finder.h"
|
|
#include "linear_finder.h"
|
|
#include "parallel_finder.h"
|
|
#include "sorted_linear_finder.h"
|
|
#include "timer.h"
|
|
#include "tree_finder.h"
|
|
#include "word_list_generator.h"
|
|
|
|
#include <cstdlib>
|
|
#include <iostream>
|
|
|
|
using std::string, std::string_view, std::vector, std::cout, std::endl;
|
|
|
|
vector<string> generate_word_list(size_t size_factor = 1) {
|
|
cout << "\ngenerating word list (" << size_factor << "x)" << endl;
|
|
|
|
Timer generator_timer;
|
|
auto word_list = WordListGenerator::generate(size_factor);
|
|
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_finder_search(Finder &finder, std::string_view name,
|
|
std::string_view search_term) {
|
|
Timer find_timer;
|
|
auto result = finder.find_prefix(search_term);
|
|
find_timer.stop();
|
|
|
|
cout << name << "(" << search_term << ") took " << find_timer << endl;
|
|
cout << "result list is " << std::distance(result.cbegin(), result.cend())
|
|
<< " element(s) long" << endl;
|
|
}
|
|
|
|
void test_finder(Finder &finder, std::string_view name) {
|
|
for (const auto &search_term : {"A", "AB", "ABC", "ABCD"}) {
|
|
test_finder_search(finder, name, search_term);
|
|
}
|
|
}
|
|
|
|
void test_linear_finder(const vector<string> &word_list) {
|
|
cout << "\nrunning linear finder" << endl;
|
|
|
|
Timer constructor_timer;
|
|
LinearFinder linear_finder(word_list);
|
|
constructor_timer.stop();
|
|
cout << "linear finder constructor took " << constructor_timer << endl;
|
|
|
|
test_finder(linear_finder, "linear finder");
|
|
}
|
|
|
|
void test_sorted_linear_finder(const vector<string> &word_list) {
|
|
cout << "\nrunning sorted linear finder" << endl;
|
|
|
|
Timer constructor_timer;
|
|
SortedLinearFinder sorted_linear_finder(word_list);
|
|
constructor_timer.stop();
|
|
cout << "sorted linear finder constructor took " << constructor_timer << endl;
|
|
|
|
test_finder(sorted_linear_finder, "sorted linear finder");
|
|
}
|
|
|
|
void test_parallel_finder(const vector<string> &word_list) {
|
|
cout << "\nrunning parallel finder" << endl;
|
|
|
|
Timer constructor_timer;
|
|
ParallelFinder parallel_finder(word_list);
|
|
constructor_timer.stop();
|
|
cout << "linear finder constructor took " << constructor_timer << endl;
|
|
|
|
test_finder(parallel_finder, "parallel finder");
|
|
}
|
|
|
|
void test_tree_finder(const vector<string> &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;
|
|
|
|
test_finder(tree_finder, "tree finder");
|
|
}
|
|
|
|
void test_grouped_finder(const vector<string> &word_list) {
|
|
cout << "\nrunning grouped finder" << endl;
|
|
|
|
Timer constructor_timer;
|
|
GroupedFinder grouped_finder(word_list);
|
|
constructor_timer.stop();
|
|
cout << "grouped finder constructor took " << constructor_timer << endl;
|
|
|
|
test_finder(grouped_finder, "grouped_finder");
|
|
}
|
|
|
|
int main(int argc, char *argv[]) {
|
|
cout << "\n== VectorSearch ==" << endl;
|
|
|
|
auto word_list = generate_word_list(5);
|
|
|
|
test_linear_finder(word_list);
|
|
test_sorted_linear_finder(word_list);
|
|
test_parallel_finder(word_list);
|
|
test_tree_finder(word_list);
|
|
test_grouped_finder(word_list);
|
|
|
|
return EXIT_SUCCESS;
|
|
}
|