VectorSearch/vector_search_cli/main.cpp

68 lines
2.0 KiB
C++
Raw Normal View History

2024-03-21 12:23:26 +00:00
#include "bucket_finder.h"
2024-03-20 15:37:00 +00:00
#include "grouped_finder.h"
#include "linear_finder.h"
#include "parallel_finder.h"
2024-03-20 19:50:43 +00:00
#include "sorted_linear_finder.h"
#include "timer.h"
2024-03-20 14:05:25 +00:00
#include "tree_finder.h"
2024-03-21 07:55:44 +00:00
#include "word_list.h"
#include <cstdlib>
2024-03-18 11:12:08 +00:00
#include <iostream>
2024-03-21 07:55:44 +00:00
using std::string, std::string_view, std::cout, std::endl;
2024-03-21 07:55:44 +00:00
WordList generate_word_list(size_t size_factor = 1) {
cout << endl << "generating word list (" << size_factor << "x)" << endl;
Timer generator_timer;
2024-03-21 07:55:44 +00:00
auto word_list = WordList::fourCaps().multiply(size_factor).shuffle();
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;
2024-03-20 15:37:00 +00:00
auto result = finder.find_prefix(search_term);
find_timer.stop();
cout << name << "(" << search_term << ") took " << find_timer << " for "
<< std::distance(result.cbegin(), result.cend()) << " results" << endl;
}
template <typename FINDER>
2024-03-21 07:55:44 +00:00
void test_finder(const WordList &word_list, string_view finder_name) {
cout << endl << "running " << finder_name << endl;
2024-03-20 14:05:25 +00:00
Timer constructor_timer;
FINDER finder(word_list);
2024-03-20 14:05:25 +00:00
constructor_timer.stop();
cout << finder_name << " constructor took " << constructor_timer << endl;
2024-03-20 14:05:25 +00:00
for (const auto &search_term :
{"A", "Z", "AB", "ZY", "ABC", "ZYX", "ABCD", "ZYXW"}) {
test_finder_search(finder, finder_name, search_term);
}
2024-03-20 14:05:25 +00:00
}
2024-03-18 11:12:08 +00:00
int main(int argc, char *argv[]) {
cout << endl << "== VectorSearch ==" << endl;
2024-03-20 19:50:43 +00:00
auto word_list = generate_word_list(5);
2024-03-21 12:23:26 +00:00
test_finder<BucketFinder>(word_list, "bucket finder");
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");
2024-03-18 11:12:08 +00:00
return EXIT_SUCCESS;
2024-03-18 11:12:08 +00:00
}