comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: [Shootout] Spellcheck.adb
Date: Tue, 26 Apr 2005 22:36:41 +0200
Date: 2005-04-26T22:36:27+02:00	[thread overview]
Message-ID: <4nm49tqq12fy.ucmt7m1938ld.dlg@40tude.net> (raw)
In-Reply-To: 1114464642.518876.137610@f14g2000cwb.googlegroups.com

On 25 Apr 2005 14:30:42 -0700, albert.bachmann@gmx.de wrote:

> on http://shootout.alioth.debian.org/ I discovered that the Ada entry
> for the "spellcheck" benchmark produces an error according to the
> information on that website. The specification for this benchmark can
> be found here:
> http://shootout.alioth.debian.org/benchmark.php?test=spellcheck&lang=all&sort=fullcpu
> 
> Since I am new to Ada I decided that it might be a good idea to
> implement a solution and see how it performs. Finally I came up with a
> naive program that performs not very well in comparison to other
> language implementations. I produced a naive implementation in C++ as
> well which solves the problem in less than half the time. The entry for
> C++ at the Shootout takes half the time of my naive solution.
> 
> Now what I'd like to ask you is how I can speed up my Ada solution? As
> I said I'm a novice and certainly there is a huge optimization
> potential here. Here is the output of 'time':

-------------- spell_check.adb -----------------
with Ada.Text_IO;        use Ada.Text_IO;
with Dictionary_Tables;  use Dictionary_Tables;

procedure Spell_Check is
   File : File_type;
   Line : String (1..130);
   Last : Natural;
   Dictionary : Table;
begin
   Open (File, In_File, "spellcheck-dict.txt");
   begin -- Reading dictionary
      loop
	   Get_Line (File, Line, Last);
         Add (Dictionary, Line (Line'First..Last), true);
      end loop;
   exception
      when End_Error =>
         null;
   end;
   Close (File);

   begin -- Reading test file
      loop
	   Get_Line (Line, Last);
         begin
   	      if Find (Dictionary, Line (Line'First..Last)) then
               null;
            end if;
         exception
            when End_Error =>
	         Put_Line (Line (Line'First..Last));
         end;
      end loop;
   exception
      when End_Error =>
         null;
   end;
end Spell_Check;
----------- dictionary_tables.adb ----------------------
with Tables;
package Dictionary_Tables is new Tables (Boolean);

The above is approximately five times faster on my computer under FC3.
Probably, because it does not use hash tables?

[ The package tables is here: http://www.dmitry-kazakov.de/ada/tables.htm ]

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  parent reply	other threads:[~2005-04-26 20:36 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-25 21:30 [Shootout] Spellcheck.adb albert.bachmann
2005-04-25 21:57 ` Spellcheck.adb Albert Bachmann
2005-04-25 23:27 ` [Shootout] Spellcheck.adb Marius Amado Alves
2005-04-26 18:04 ` Spellcheck.adb Matthew Heaney
2005-04-26 19:36 ` [Shootout] Spellcheck.adb David Sauvage
2005-04-26 20:50   ` Spellcheck.adb Albert Bachmann
2005-04-27 15:11     ` Spellcheck.adb Matthew Heaney
2005-04-27 22:49       ` Spellcheck.adb Albert Bachmann
2005-04-27 23:35         ` Spellcheck.adb Marius Amado Alves
2005-04-27 23:58           ` Spellcheck.adb Albert Bachmann
2005-04-28  0:19             ` Spellcheck.adb Marius Amado Alves
2005-04-29 10:22               ` Spellcheck.adb Albert Bachmann
2005-04-28  0:58             ` Spellcheck.adb Matthew Heaney
2005-04-29 10:19               ` Spellcheck.adb Albert Bachmann
2005-04-28  0:41         ` Spellcheck.adb Matthew Heaney
2005-04-28 21:20           ` Spellcheck.adb Simon Wright
2005-04-29 10:05           ` Spellcheck.adb Albert Bachmann
2005-04-29 12:35             ` Spellcheck.adb Matthew Heaney
2005-04-26 21:21   ` Spellcheck.adb Albert Bachmann
2005-04-26 22:04     ` Spellcheck.adb David Sauvage
2005-04-26 20:36 ` Dmitry A. Kazakov [this message]
2005-04-26 21:50   ` [Shootout] Spellcheck.adb David Sauvage
2005-04-27  8:40     ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox