VectorSearch/vector_search_cli/main.cpp

65 lines
2.0 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 << endl << "generating 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, string_view name,
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;
}
template <typename FINDER>
void test_finder(const vector<string> &word_list, string_view finder_name) {
cout << endl << "running " << finder_name << endl;
Timer constructor_timer;
FINDER finder(word_list);
constructor_timer.stop();
cout << finder_name << " constructor took " << constructor_timer << endl;
for (const auto &search_term : {"A", "AB", "ABC", "ABCD"}) {
test_finder_search(finder, finder_name, search_term);
}
}
int main(int argc, char *argv[]) {
cout << "\n== VectorSearch ==" << endl;
auto word_list = generate_word_list(5);
test_finder<LinearFinder>(word_list, "linear finder");
test_finder<SortedLinearFinder>(word_list, "sorted linear finder");
test_finder<ParallelFinder>(word_list, "parallel finder");
test_finder<TreeFinder>(word_list, "tree finder");
test_finder<GroupedFinder>(word_list, "grouped finder");
return EXIT_SUCCESS;
}