Path: csiph.com!au2pb.net!feeder.erje.net!1.eu.feeder.erje.net!news-2.dfn.de!news.dfn.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Ian Collins Newsgroups: comp.lang.c++ Subject: Re: What practice can get speed improvement in C++? Date: Thu, 06 Aug 2015 17:42:18 +1200 Lines: 37 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net fJavL+P4PzatnjSKftSEcQZJXYiPirWvitoFGLzM07JLtDbpsp Cancel-Lock: sha1:pEmQZzycHiER++R8qBmXAgFVBRA= User-Agent: Mozilla/5.0 (X11; SunOS i86pc; rv:17.0) Gecko/17.0 Thunderbird/17.0 In-Reply-To: Xref: csiph.com comp.lang.c++:37357 woodbrian77@gmail.com wrote: > > How about comparing these two programs: > > #include > > int main () > { > for (int i = 0; i < 4000000; ++i){ > char s[200]; > ::strncpy(s, "We few; we happy few; we band of brothers.", sizeof(s)); > } > } > > and > > #include > > int main () > { > for (int i = 0; i < 4000000; ++i){ > ::std::string s = "We few; we happy few; we band of brothers."; > } > } A fairer comparison would be int main () { std::string s; for (int i = 0; i < 4000000; ++i){ s = "We few; we happy few; we band of brothers."; } } -- Ian Collins