From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31555 invoked by alias); 6 Oct 2014 16:56:48 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 31524 invoked by uid 48); 6 Oct 2014 16:56:42 -0000 From: "andi-gcc at firstfloor dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/63466] New: sstream is very slow Date: Mon, 06 Oct 2014 16:56:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 5.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: andi-gcc at firstfloor dot org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-10/txt/msg00407.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63466 Bug ID: 63466 Summary: sstream is very slow Product: gcc Version: 5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: andi-gcc at firstfloor dot org sstream is very slow. Comparing two simple programs that parse a stream with C and with sstream. The sstream version is an order of magnitude slower. gcc version 4.9.1 20140423 (prerelease) (GCC) # C++ % time ./a.out < testfile real 0m0.893s user 0m0.888s sys 0m0.004s # C time ./tstream-c < testfile real 0m0.032s user 0m0.030s sys 0m0.001s Here's a profile. 16.13% a.out libc-2.18.so [.] _IO_getc 10.39% a.out libc-2.18.so [.] _IO_ungetc 9.15% a.out libstdc++.so.6.0.20 [.] std::basic_istream >& std::getline, std::allocator >(std::basic_istream >&, std::basic_string, std::allocator >&, char) 7.87% a.out libstdc++.so.6.0.20 [.] __dynamic_cast 4.99% a.out libc-2.18.so [.] __GI___strcmp_ssse3 3.95% a.out libstdc++.so.6.0.20 [.] std::basic_istream >& std::operator>>, std::allocator >(std::basic_istream >&, std::basic_string, std::allocator >&) 3.89% a.out libc-2.18.so [.] _int_free 2.79% a.out libstdc++.so.6.0.20 [.] __cxxabiv1::__vmi_class_type_info::__do_dyncast(long, __cxxabiv1::__class_type_info::__sub_kind, __cxxabiv1::__class_type_info const*, void const*, __cxxabiv1::__class_type_info const*, void const*, __cxxabiv1::__class_type_info::__dyncast_result&) const 2.65% a.out a.out [.] main 2.58% a.out libc-2.18.so [.] malloc 2.30% a.out libstdc++.so.6.0.20 [.] __cxxabiv1::__si_class_type_info::__do_dyncast(long, __cxxabiv1::__class_type_info::__sub_kind, __cxxabiv1::__class_type_info const*, void const*, __cxxabiv1::__class_type_info const*, void const*, __cxxabiv1::__class_type_info::__dyncast_result&) const 1.96% a.out libc-2.18.so [.] _int_malloc 1.86% a.out libstdc++.so.6.0.20 [.] std::istream::sentry::sentry(std::istream&, bool) 1.55% a.out libc-2.18.so [.] _IO_sputbackc 1.51% a.out libstdc++.so.6.0.20 [.] __gnu_cxx::stdio_sync_filebuf >::underflow() Test case: Generate test file: perl -e 'for($i=0;$i<1000000;$i++) { printf("%d %d\n", $i, $i); } ' > testfile C++ version: #include #include #include using namespace std; void __attribute__((noinline, noclone)) func(string &, string &) { } int main() { string line; while (getline(cin, line)) { istringstream iss(line); string index, s; if (!(iss >> index >> s)) continue; func(index, s); } return 0; } C version: #define _GNU_SOURCE 1 #include #include void __attribute__((noinline, noclone)) func(char *a, char *b) { } int main() { char *line = NULL; size_t linelen = 0; while (getline(&line, &linelen, stdin) > 0) { char *p = line; char *a = strsep(&p, " \t\n"); char *b = strsep(&p, " \t\n"); func(a, b); } return 0; }