Re: Ada Shootout program for K-Nucleotide (patches)



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;
.



Relevant Pages

  • Re: Get the path and namefile in run time
    ... function Get_Path_Only return String; ... -- This returns the first N characters of the program name. ... end loop; ...
    (comp.lang.ada)
  • Re: Parse String
    ... it picking up substrings beginning with 'f' followed by hyphens, ... Function gnaf(s As String) As Variant ... Exit Do 'inner Do ... Loop ...
    (microsoft.public.excel.programming)
  • Re: Newbie needs help
    ... You want to exit the loop when the user types ... void ParseLine (const string& cInput, ...
    (comp.lang.cpp)
  • Avoiding side effects
    ... function Strip (Remove_This: in String) return String ... The main program is then merely a loop where I alternate between ... exit when EOF_Reached; ...
    (comp.lang.ada)
  • Re: new line character in a string
    ... is there any other mechanism to use newline character in a PS string? ... {%loop over file ... dup currentfile exch readstring exch ...
    (comp.lang.postscript)