From: Georg Bauhaus <rm.dash-bauhaus@futureapps.de>
Subject: Re: File output and buffering
Date: Wed, 20 Aug 2008 15:19:56 +0200
Date: 2008-08-20T15:19:56+02:00 [thread overview]
Message-ID: <48ac19fc$0$11747$9b4e6d93@newsspool1.arcor-online.net> (raw)
In-Reply-To: <b3f16c6a-742c-43c3-baec-9533db25e423@r66g2000hsg.googlegroups.com>
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 <stdio.h>
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 <iostream>
int main()
{
std::string s =
"********************************************************************";
for (int k = 0; k < 50000; ++k)
{
s[k % 68] = static_cast<char>(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
next prev parent reply other threads:[~2008-08-20 13:19 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-19 20:27 File output and buffering Maciej Sobczak
2008-08-20 6:45 ` Georg Bauhaus
2008-08-20 8:43 ` Maciej Sobczak
2008-08-20 8:59 ` Maciej Sobczak
2008-08-20 9:21 ` Dmitry A. Kazakov
2008-08-20 14:44 ` Maciej Sobczak
2008-08-20 15:39 ` Dmitry A. Kazakov
2008-08-21 7:10 ` Maciej Sobczak
2008-08-21 9:24 ` Dmitry A. Kazakov
2008-08-21 20:54 ` Maciej Sobczak
2008-08-21 21:27 ` Dmitry A. Kazakov
2008-08-22 11:53 ` Maciej Sobczak
2008-08-22 13:22 ` Dmitry A. Kazakov
2008-08-22 21:41 ` Maciej Sobczak
2008-08-23 10:25 ` Dmitry A. Kazakov
2008-08-23 13:41 ` Steve
2008-08-23 14:33 ` Dmitry A. Kazakov
[not found] ` <Q7adnfmCI6Ly6S3VnZ2dnUVZ_jOdnZ2d@earthlink.com>
2008-08-23 22:00 ` Maciej Sobczak
2008-08-20 13:19 ` Georg Bauhaus [this message]
2008-08-20 14:41 ` Maciej Sobczak
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox