Bug 82345 - low performance (comparing to clang)
Summary: low performance (comparing to clang)
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 7.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2017-09-27 16:11 UTC by Eugene
Modified: 2017-10-12 16:54 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-09-27 00:00:00


Attachments
source code (136.03 KB, application/gzip)
2017-09-27 16:25 UTC, Eugene
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Eugene 2017-09-27 16:11:22 UTC
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)
Comment 1 Eugene 2017-09-27 16:13:36 UTC
Source file https://yadi.sk/d/FqXH-4Y63NGeSw
Comment 2 Jonathan Wakely 2017-09-27 16:22:14 UTC
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/
Comment 3 Eugene 2017-09-27 16:25:12 UTC
Created attachment 42249 [details]
source code
Comment 4 Jonathan Wakely 2017-09-27 17:02:20 UTC
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");
  }
}
Comment 5 Jonathan Wakely 2017-09-27 17:06:24 UTC
(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.