[fpc-devel] Benchmark for FreePascal
Michael Van Canneyt
michael at freepascal.org
Wed Dec 14 20:21:18 CET 2005
On Wed, 14 Dec 2005, Jonas Maebe wrote:
>
> On 10 dec 2005, at 22:09, darekM wrote:
>
> > I've see that reverse-complement benchmark <http://
> > shootout.alioth.debian.org/benchmark.php?test=revcomp&lang=all> for FPC
> > is very slow. I discover, that problem is with readln, that function
> > consume about 90% of time.
>
> In my test (Mac OS X/PPC, rtl and program compiled with register variables,
> text buffer of 64kb) readln's overheid is negligible. The large cost comes
> from writeln. The reason the C version is so much faster is because its output
> is buffered as well. We automatically flush the output after each writeln
> (i.e. after each writeln of 60 characters), while in C this only happens at
> the very end of the program for 128kb of characters at a time.
Normally, You can speed that up considerably by doing the following:
program testp;
uses dos; // Needed for TextRec...
Var
F : Text;
Buf : Array[1..100000] of char;
I : Integer;
begin
Assign(F,'');
Rewrite(F);
SetTextBuf(F,Buf); // Allocate HUGE buffer
TextRec(F).FlushFunc:=Nil; // Disable flushing after each writeln().
For I:=1 to 10000 do
Writeln(F,'teststring');
Close(F); // Will flush.
end.
If you strace that, you'll see that the whole buffer is written to screen in one
big gulp, instead of 256 chars per write.
In fact, I think maybe we should do the
TextRec(F).FlushFunc:=Nil; // Disable flushing after each writeln().
In SetTextBuf if the file is open for writing, as otherwise the settextbuf
is meaningless. Or add a DisableFlushText() call to the system unit.
(to avoid dragging the Dos unit in if you want this)
Michael.
More information about the fpc-devel
mailing list