String search is slow for this code. $ g++ -O2 -DNDEBUG -std=c++14 gcc_perf_buf.cc && time ./a.out shodan/huge01.txt real 0m0.470s user 0m0.367s sys 0m0.104s $ clang++ -O2 -DNDEBUG -std=c++14 gcc_perf_buf.cc && time ./a.out shodan/huge01.txt real 0m0.248s user 0m0.179s sys 0m0.069s $ gcc --version gcc (Ubuntu 7.2.0-7ubuntu1) 7.2.0 Copyright (C) 2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ lsb_release -d Description: Ubuntu Artful Aardvark (development branch)
Source file https://yadi.sk/d/FqXH-4Y63NGeSw
Please attach the source here, don't link to somewhere else. Compress it if needed, or better still, reduce it: https://gcc.gnu.org/wiki/A_guide_to_testcase_reduction https://gcc.gnu.org/bugs/
Created attachment 42249 [details] source code
When I compare the performance of this similar program on a text file of 4 million lines I see gcc performs slightly better: #include <fstream> #include <string> #include <experimental/string_view> int main(int , char**argv) { std::ifstream in(argv[1]); std::string line; while (std::getline(in, line)) { auto pos = std::experimental::string_view(line).find("http"); } }
(In reply to Eugene from comment #3) > Created attachment 42249 [details] > source code Thanks, GCC does indeed perform worse for the version using boost::string_view.