std::boyer_moore_horspool_searcher slower than the auto cx = data[i].find(pat)

106 Views Asked by At

I am testing the text lines search speed for 1M lines.

I generate 1M vector string data , each has a text line . pat is std::string search keyword.

c++ standard std::string.find 5 tees faster than the Boyer.

how it could be possible?

for (int i = 1; i <= 5; i++) {
  std::chrono::steady_clock::time_point begin =
      std::chrono::steady_clock::now();
  for (int i = 1; i <= val; ++i) {
    // std::cout << i << "  val:" << val << endl;
    // search(std::to_string(i) + fwtxt + std::to_string(i), pat);
    auto cx = data[i].find(pat); //!= std::string::npos)

    // auto it = std::search(data[i].begin(), data[i].end(),
    //                       std::boyer_moore_horspool_searcher(pat.begin(),
    //                       pat.end()));

    // cout << cx << endl;           // std::cout << "found!" << '\n';

    // search(data[i], pat);
  }

  std::cout << ":: " << data[(rand() % 100)] << endl;
  std::chrono::steady_clock::time_point end =
      std::chrono::steady_clock::now();

  std::cout << "Time difference = "
            << std::chrono::duration_cast<std::chrono::milliseconds>(end -
                                                                     begin)
                   .count()
            << "[ms]" << std::endl;
}
0

There are 0 best solutions below