This repository has been archived on 2024-12-15. You can view files and clone it, but cannot push or open issues or pull requests.
VectorSearch/vector_search_cli/main.cpp

93 lines
2.5 KiB
C++

#include "grouped_finder.h"
#include "linear_finder.h"
#include "parallel_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() {
cout << "\ngenerating word list" << endl;
Timer generator_timer;
auto word_list = WordListGenerator::generate(5);
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;
LinearFinder linear_finder(word_list);
test_finder(linear_finder, "linear finder");
}
void test_parallel_finder(const vector<string> &word_list) {
cout << "\nrunning parallel finder" << endl;
ParallelFinder parallel_finder(word_list);
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();
test_linear_finder(word_list);
test_parallel_finder(word_list);
test_tree_finder(word_list);
test_grouped_finder(word_list);
return EXIT_SUCCESS;
}