Re: Ada Shootout program for K-Nucleotide (patches)
- From: Georg Bauhaus <rm.tsoh.plus-bug.bauhaus@xxxxxxxxxxxxxxxxxx>
- Date: Sun, 02 Aug 2009 14:55:57 +0200
Ludovic Brenta wrote:
Georg Bauhaus wrote on comp.lang.ada:
This is about the K-Nucleotide program at the
Computer Language Benchmark Game,http://shootout.alioth.debian.org/u32/benchmark.php?test=knucleotide&...
where some Ada programs have started to fail.
In order to have one of them work again, I have patched
knucleotide.gnat, with some success. New version is here:http://home.arcor.de/bauhaus/Ada/knucleotide.gnat
Comments? Does it work on your machine?
The two changes:
1 - [stack exhaustion] a loop reading input lines into an
ubounded string replaces the recursive String "&"ing
procedure. (Noting that the input text file is ~240MB ...)
2 - [heavy bounded strings] a lightweight bounded string ADT
replaces an instance of Generic_Bounded_Length, yielding
an improved running time of ~22s down from ~30s for
the 2,500,000 case.
Still, on a relatively small virtual machine running 64bit
Debian, the program cannot handle the 25,000,000 case.
I note that both Martin and yourself use Ada.Text_IO (especially
Read_Line) which is notoriously slow. I would use Character'Read and
a finite state machine to detect the portion of the input file to be
processed, then to fill in the buffer. That should be faster.
Not sure that Character'Read will really be faster.
The following Getline has left me unconvinced.
I made a simple test just reading big files and
measuring the time; Text_IO.Get_Line wins on Windows
and even more or Debian.
Also, unless there is bug in the program below,
using Streams and then child packages of Text_IO
for output formatting, seems to confuse the
I/O system. (Would we be shooting ourselves in
the foot anyway?)
GNAT.IO is, I think, getting us in trouble; it doesn't
signal End_Error, if I'm not mistaken.
with Ada.Text_IO.Text_Streams;
procedure Getline (Item: in out String; Last : out Natural) is
--
-- Input via Character'Read.
-- Assume Unix or Windows line ending conventions.
--
Stdin: constant Ada.Text_IO.Text_Streams.Stream_Access :=
Ada.Text_IO.Text_Streams.Stream (Ada.Text_IO.Standard_Input);
C : Character;
begin
Last := Item'First - 1;
loop
Character'Read (Stdin, C);
exit when C = ASCII.LF;
if C /= ASCII.CR then
Last := Last + 1;
Item (Last) := C;
end if;
exit when Last = Item'Last;
end loop;
end Getline;
.
- Follow-Ups:
- Re: Ada Shootout program for K-Nucleotide (patches)
- From: Ole-Hjalmar Kristensen
- Re: Ada Shootout program for K-Nucleotide (patches)
- References:
- Ada Shootout program for K-Nucleotide (patches)
- From: Georg Bauhaus
- Re: Ada Shootout program for K-Nucleotide (patches)
- From: Ludovic Brenta
- Ada Shootout program for K-Nucleotide (patches)
- Prev by Date: Re: exit a program
- Next by Date: Re: exit a program
- Previous by thread: Re: Ada Shootout program for K-Nucleotide (patches)
- Next by thread: Re: Ada Shootout program for K-Nucleotide (patches)
- Index(es):
Relevant Pages
|