From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,68494635acddb77e X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news2.google.com!eweka.nl!lightspeed.eweka.nl!82.197.223.104.MISMATCH!feeder4.cambrium.nl!feed.tweaknews.nl!193.141.40.65.MISMATCH!npeer.de.kpn-eurorings.net!npeer-ng1.kpn.DE!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Wed, 20 Aug 2008 15:19:56 +0200 From: Georg Bauhaus User-Agent: Thunderbird 2.0.0.16 (Macintosh/20080707) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: File output and buffering References: <60a35fd4-e5a6-4aa0-a73f-6815ce7e92fc@f36g2000hsa.googlegroups.com> <4af2f934-7458-4370-b325-c38e3a4068b8@s50g2000hsb.googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-ID: <48ac19fc$0$11747$9b4e6d93@newsspool1.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 20 Aug 2008 15:19:56 CEST NNTP-Posting-Host: 524d8c03.newsspool1.arcor-online.net X-Trace: DXC=aL5Y6dnDPA0gP]QSEBQ^d4ic==]BZ:af>4Fo<]lROoR14nDHegD_]R5i>ZD03E=X21;9OJDO8_SK6NSZ1n^B98i:>@ldKe6I7Z2 X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:7403 Date: 2008-08-20T15:19:56+02:00 List-Id: Maciej Sobczak schrieb: >> In particular: how can I *flush* the buffer? > > By calling Ada.Text_IO.Flush. > > Which means that Georg Bauhaus fell into the trap of my confusion. :-) Sort of, but, as you say, the issue remains. > Still valid question: > >> 3. Why is buffered Ada.Text_IO as slow as non-buffered C's stdio? Who >> is eating the 20x factor? Text_IO is demonstrably slow. There are some speedy shortcuts in the GNAT implementation of Put (e.g. Write_Buf). But AFAICS there is (and has to be) a lot of protecting code around the OS calls. Using the following stupid programs for comparison, and using strace, I get 3370 calls to write(2) from C, but 50_000 from both C++ and Ada. Among other things open to speculation (or open to inspection). There are 4622 different lines in the 50_000 lines of output. I think that if you have a formatted (constrained) string, system I/O using fputs and flush might be a lot faster (modulo threading issues). #include int main() { char s[68 + 1] = "********************************************************************"; for (int k = 0; k < 50000; ++k) { s[k % 68] = (char)(33 + k % 67); fputs(s, stdout), fputc('\n', stdout); } return 0; } #include int main() { std::string s = "********************************************************************"; for (int k = 0; k < 50000; ++k) { s[k % 68] = static_cast(33 + k % 67); std::cout << s << std::endl; } return 0; } with Ada.Text_IO; procedure Ada_Wrt is S: String := (1 .. 68 => '*'); begin for K in 0 .. 50_000 - 1 loop S(1 + K rem 68) := Character'Val(33 + K rem 67); Ada.Text_IO.Put_Line(S); end loop; end Ada_Wrt; -- Georg Bauhaus Y A Time Drain http://www.9toX.de