From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7664 invoked by alias); 16 Oct 2002 19:20:22 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 7655 invoked from network); 16 Oct 2002 19:20:19 -0000 Received: from unknown (HELO smtp.web.de) (217.72.192.151) by sources.redhat.com with SMTP; 16 Oct 2002 19:20:19 -0000 Received: from [129.187.26.86] (helo=mephisto) by smtp.web.de with asmtp (WEB.DE(Exim) 4.75 #2) id 181tiM-0006rd-00 for gcc-help@gcc.gnu.org; Wed, 16 Oct 2002 21:20:18 +0200 Content-Type: text/plain; charset="iso-8859-1" From: Sebastian Huber To: gcc-help@gcc.gnu.org Subject: Re: Lexical conversion. Date: Wed, 16 Oct 2002 12:20:00 -0000 References: <2F05A390F72A0A409390E016D23E45E8042DBE44@ns-bco-mse4.im.battelle.org> In-Reply-To: <2F05A390F72A0A409390E016D23E45E8042DBE44@ns-bco-mse4.im.battelle.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200210162053.16197.sebastian-huber@web.de> X-SW-Source: 2002-10/txt/msg00202.txt.bz2 On Wednesday 16 October 2002 06:03, Moore, Mathew L wrote: > > > #include > > > > > > string convert (const int number) { > > > ostringstream ostr; > > > ostr << number; > > > return ostr.str (); > > > } > > > > Sigh! I decided (especially as most the cases I worry about > > are in 0-9) to > > implement it like so.. (I unit tested it so I'm reasonable > > confident it > > works and its about 3 times faster in the general case than > > using printf) > > Why do you suppose there is such a great speed improvement with the code > below? It seems to me that snprintf() should be able to optimize this ta= sk > quite effectively. The only overhead should be the parsing of the format > string, which in this case would be very simple. > If you can use you should prefer it. Stringstreams are likely the= =20 most general and efficient way to do such conversions with C/C++. If you kn= ow=20 more about the input, you can optimize of course. Ciao Sebastian