59 lines
1.4 KiB
C++
59 lines
1.4 KiB
C++
#include <iostream>
|
|
#include <string>
|
|
#include <vector>
|
|
#include <chrono>
|
|
|
|
#include "SearchJob.hpp"
|
|
|
|
using namespace std::chrono;
|
|
|
|
// Type of our hay stack: a list of strings
|
|
typedef std::vector<std::string> WordList;
|
|
|
|
void create_testdata(WordList& words)
|
|
{
|
|
const char start = 'A';
|
|
const char end = 'Z';
|
|
char str[4] = { 'A', 'A', 'A', 'A' };
|
|
|
|
for (str[0] = start; str[0] <= end; str[0]++)
|
|
for (str[1] = start; str[1] <= end; str[1]++)
|
|
for (str[2] = start; str[2] <= end; str[2]++)
|
|
for (str[3] = start; str[3] <= end; str[3]++)
|
|
words.push_back(std::string(str, 4));
|
|
}
|
|
|
|
|
|
int main()
|
|
{
|
|
std::cout << "Hello World." << std::endl;
|
|
|
|
|
|
WordList test_data;
|
|
|
|
{
|
|
steady_clock::time_point t1 = steady_clock::now();
|
|
create_testdata(test_data);
|
|
steady_clock::time_point t2 = steady_clock::now();
|
|
duration<double> time_span = duration_cast<duration<double>>(t2 - t1);
|
|
|
|
std::cout << "It took me " << time_span.count() << " seconds to create " << test_data.size() << " words." << std::endl;
|
|
}
|
|
|
|
|
|
{
|
|
SearchJob<WordList::const_iterator> job(test_data.begin(), test_data.end(), "ABC");
|
|
steady_clock::time_point t1 = steady_clock::now();
|
|
job.run();
|
|
steady_clock::time_point t2 = steady_clock::now();
|
|
duration<double> time_span = duration_cast<duration<double>>(t2 - t1);
|
|
|
|
std::cout << "It took me " << time_span.count() << " seconds to find " << job.GetResult().size() << " matches." << std::endl;
|
|
}
|
|
|
|
std::cout << std::endl;
|
|
|
|
|
|
return 0;
|
|
}
|