public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "ctsa at u dot washington dot edu" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/14061] New: poor performance of std::sort on large lexicographic c-string sort Date: Sat, 07 Feb 2004 08:07:00 -0000 [thread overview] Message-ID: <20040207080740.14061.ctsa@u.washington.edu> (raw) I've encountered a performance bug for string sorting using std::sort which I can't diagnose; this has been reduced to a minimal testcase which compares std::sort and qsort: sort_bug.cc """ #include <cstdlib> #include <cstring> #include <algorithm> #include <iostream> int cmpcount = 0; int qsort_cmp(const void* ptr1,const void* ptr2){ if( (++cmpcount)%100000 == 0 ) std::cerr << cmpcount << std::endl; return( strcmp(*((char**) ptr1),*((char**) ptr2))); } struct functor_cmp { bool operator()(const char* a, const char* b){ if( (++cmpcount)%100000 == 0 ) std::cerr << cmpcount << std::endl; return strcmp(a,b) == -1; } }; int main() { const int len = 1000000; char* big_str = new char[len]; for(int i=0;i<len-1;++i){ big_str[i] = "ACGT"[(int) (4.*random()/(RAND_MAX+1.))]; } big_str[len-1] = 0; char** sub_strs = new char*[len]; for(int i=0;i<len;++i){ sub_strs[i] = big_str+i; } // qsort runs well, std::sort reaches ~2000000 iterations and bogs down #if 0 qsort(sub_strs,len,sizeof(char*),qsort_cmp); #else std::sort(sub_strs,sub_strs+len,functor_cmp()); #endif delete [] sub_strs; delete [] big_str; } """ The performance bug shows up at all optimization levels I've tried; if the qsort/std::sort versions are compiled without any optimization (gcc 3.4, specs below) the two versions complete the sort in 3s/390s respectively -- nothing in memory is being swapped to disk in either case. Compiling the same code with the Intel 7.1 compiler (no optimizaion) yeilds almost equal sort times between the two versions, about 3s/3s . The platform specs: 1 Ghz Pentium III Redhat 7.1 $ rpm -q glibc binutils glibc-2.2.4-32 binutils-2.10.91.0.2-3 I've tested and found this bug with gcc 3.3.2 and 3.4, here's the the gcc 3.4 version I'm using: $ g++34 -v Reading specs from /home/ctsa/opt/gcc-3.4-20040206/i686-linux/lib/gcc/i686-pc-linux-gnu/3.4.0/specs Configured with: ../gcc-3.4-20040206/configure --prefix=/home/ctsa/opt/gcc-3.4-20040206 --exec-prefix=/home/ctsa/opt/gcc-3.4-20040206/i686-linux --program-suffix=34 --disable-checking --enable-concept-checks --enable-languages=c,c++ Thread model: posix gcc version 3.4.0 20040206 (prerelease) -- Summary: poor performance of std::sort on large lexicographic c- string sort Product: gcc Version: 3.4.0 Status: UNCONFIRMED Severity: normal Priority: P2 Component: libstdc++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: ctsa at u dot washington dot edu CC: gcc-bugs at gcc dot gnu dot org GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14061
next reply other threads:[~2004-02-07 8:07 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2004-02-07 8:07 ctsa at u dot washington dot edu [this message] 2004-02-07 8:37 ` [Bug libstdc++/14061] " pinskia at gcc dot gnu dot org 2004-02-07 16:03 ` pcarlini at suse dot de 2004-02-07 22:09 ` ctsa at u dot washington dot edu
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20040207080740.14061.ctsa@u.washington.edu \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).