refactor: move test cli to own project

This commit is contained in:
Michael Mandl 2024-03-19 17:34:58 +01:00
parent 32a1cd7533
commit e648a82c42
Signed by: mandlm
GPG key ID: 4AA25D647AA54CC7
3 changed files with 17 additions and 12 deletions

View file

@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.20)
project(
vector_search_cli
VERSION 0.1.0
LANGUAGES CXX)
add_executable(vector_search_cli main.cpp)
target_link_libraries(vector_search_cli lib_vector_search)
target_compile_features(vector_search_cli PRIVATE cxx_std_20)

View file

@ -0,0 +1,66 @@
#include "linear_finder.h"
#include "parallel_finder.h"
#include "timer.h"
#include "word_list_generator.h"
#include <cstdlib>
#include <iostream>
#include <thread>
using std::string, std::string_view, std::vector, std::thread, std::cout,
std::endl;
vector<string> generate_word_list() {
cout << "\ngenerating word list" << endl;
Timer generator_timer("word list generator");
auto word_list = WordListGenerator().generate();
generator_timer.stop();
cout << "word list is " << word_list.size() << " element(s) long" << endl;
return word_list;
}
void test_linear_finder(const vector<string> &word_list) {
cout << "\nrunning linear finder" << endl;
Timer constructor_timer("linear finder constructor");
LinearFinder linear_finder(word_list);
constructor_timer.stop();
Timer find_timer("linear finder find");
auto result = linear_finder.find_prefix("ABCD");
find_timer.stop();
cout << "result list is " << result.size() << " element(s) long" << endl;
}
void test_parallel_finder(const vector<string> &word_list) {
cout << "\nrunning parallel finder" << endl;
const size_t thread_count = thread::hardware_concurrency();
cout << "using " << thread_count << " threads" << endl;
Timer constructor_timer("parallel finder constructor");
ParallelFinder parallel_finder(word_list, thread_count);
constructor_timer.stop();
Timer find_timer("parallel finder find");
auto result = parallel_finder.find_prefix("ABCD");
find_timer.stop();
cout << "result list is " << result.size() << " 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);
return EXIT_SUCCESS;
}