refactor: return numerical value from timer

This commit is contained in:
Michael Mandl 2024-03-20 09:58:40 +01:00
parent f7634bdd95
commit 64ae4c62a9
Signed by: mandlm
GPG key ID: 4AA25D647AA54CC7
3 changed files with 17 additions and 16 deletions

View file

@ -13,10 +13,11 @@ using std::string, std::string_view, std::vector, std::thread, std::cout,
vector<string> generate_word_list() {
cout << "\ngenerating word list" << endl;
Timer generator_timer("word list generator");
Timer generator_timer;
auto word_list = WordListGenerator().generate();
generator_timer.stop();
cout << "word list generator took " << generator_timer.us() << " µs" << endl;
cout << "word list is " << word_list.size() << " element(s) long" << endl;
return word_list;
@ -25,14 +26,15 @@ vector<string> generate_word_list() {
void test_linear_finder(const vector<string> &word_list) {
cout << "\nrunning linear finder" << endl;
Timer constructor_timer("linear finder constructor");
Timer constructor_timer;
LinearFinder linear_finder(word_list);
constructor_timer.stop();
Timer find_timer("linear finder find");
Timer find_timer;
auto result = linear_finder.find_prefix("ABCD");
find_timer.stop();
cout << "linear finder took " << find_timer.us() << " µs" << endl;
cout << "result list is " << result.size() << " element(s) long" << endl;
}
@ -43,14 +45,15 @@ void test_parallel_finder(const vector<string> &word_list) {
cout << "using " << thread_count << " threads" << endl;
Timer constructor_timer("parallel finder constructor");
Timer constructor_timer;
ParallelFinder parallel_finder(word_list, thread_count);
constructor_timer.stop();
Timer find_timer("parallel finder find");
Timer find_timer;
auto result = parallel_finder.find_prefix("ABCD");
find_timer.stop();
cout << "parallel finder took " << find_timer.us() << " µs" << endl;
cout << "result list is " << result.size() << " element(s) long" << endl;
}