Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c++ Subject: Re: rational numbers Date: Wed, 22 Sep 2021 07:18:18 -0700 Organization: None to speak of Lines: 32 Message-ID: <87r1dgn179.fsf@nosuchdomain.example.com> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="b5fd9637bf49c8f43a3bd672d60f3caf"; logging-data="32082"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX182scDw9+vdKAFVXhTsXZo5" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:pMvhlapoMTl1LzuU9IqiBTqlxrM= sha1:NbcCvQnwYi+lBYyxZdCJaAq57/s= Xref: csiph.com comp.lang.c++:81421 Bart writes: [...] > #include > > int main() > { std::string s=""; > char t[100]; > > for (int i=1; i<=10000000; ++i) { > s += itoa(i,t,10); > s += ' '; > } > > std::cout << "S.size = " << s.size() << "\n"; > } > > Compiled as g++ -O2, this runs in 1.3 seconds on my machine. My script > language might take only twice as long, but is much simpler and > quicker to write. I'm a little surprised that compiles. It doesn't on my Linux system, but it does under Cygwin (but fails with "g++ -std=c++11 -pedantic"). itoa() is non-standard, and apparently it's provided by newlib (Cygwin) but not by GNU libc (most Linux systems). std::to_string() (introduced in C++11) is the C++ equivalent. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for Philips void Void(void) { Void(); } /* The recursive call of the void */