From: Georg Bauhaus <rm.tsoh.plus-bug.bauhaus@maps.futureapps.de>
Subject: Re: Ada Shootout program for K-Nucleotide (patches)
Date: Fri, 07 Aug 2009 10:53:59 +0200
Date: 2009-08-07T10:54:02+02:00 [thread overview]
Message-ID: <4a7bebaa$0$30224$9b4e6d93@newsspool1.arcor-online.net> (raw)
In-Reply-To: <h5fm0g$a4u$1@news.tornevall.net>
Jeffrey R. Carter wrote:
> How about
>
> subtype Index is Stream_Element_Offset range
> Stream_Element_Offset(Item'First) .. Stream_Element_Offset(Item'Last
> + 1);
> subtype XString is String (Item'First .. Item'Last + 1);
>
> followed by
>
> Stream_IO.Write (stdout, To_Bytes (Item & ASCII.LF) );
Shorter, and consistently faster when strings are short (10:11).
I'll add this.
I don't know, though, whether or not exchanging one "&" for
one less Stream_IO.Write is also good when strings are larger,
because of the copying in "&", CPU cache sizes, ...
The test results I get from the program below vary a lot
for anything but the short string (1..70) variant.
Since the test has been run in a VM on top of Vista, I don't
trust the timings that much anyway. Maybe the order
of tests has an effect, too? Does somebody have a stable
Linux (or Unix) test environment? Could you try this?
package Print_Pak is
procedure Print_Old (Item : String);
procedure Print (Item : String);
end Print_Pak;
with Ada.Real_Time; use Ada.Real_Time;
with Print_Pak;
procedure Test_Print is
type String_Kind is (Short_Strings,
Medium_Strings,
Long_Strings);
type String_Access is access String;
type Run is record
Data : String_Access;
Rounds : Positive;
end record;
Test_Size : constant := 50_000_000;
Max_Run : constant array (String_Kind) of Run :=
(Short_Strings =>
(Data => new String(1 .. 70 * 1),
Rounds => Test_Size / 1),
Medium_Strings =>
(Data => new String(1 .. 70 * 100),
Rounds => Test_Size / 100),
Long_Strings =>
(Data => new String(1 .. 70 * 10_000),
Rounds => Test_Size / 10_000));
Start, Stop: array (String_Kind) of Time;
procedure Terminal (Message : String) is separate;
begin
Old: for Kind in Short_Strings .. Long_Strings loop
Start(Kind) := Clock;
for K in 1 .. Max_Run(Kind).Rounds loop
Print_Pak.Print_Old (Max_Run(Kind).Data.all);
end loop;
Stop(Kind) := Clock;
Terminal ("Print_Old, "
& String_Kind'Image(Kind)
& ": "
& Duration'Image (To_Duration (Stop(Kind)
- Start(Kind))));
end loop Old;
for Kind in Short_Strings .. Long_Strings loop
Start(Kind) := Clock;
for K in 1 .. Max_Run(Kind).Rounds loop
Print_Pak.Print (Max_Run(Kind).Data.all);
end loop;
Stop(Kind) := Clock;
Terminal ("Print, "
& String_Kind'Image(Kind)
& ": "
& Duration'Image (To_Duration (Stop(Kind)
- Start(Kind))));
end loop;
end Test_Print;
with Ada.Text_IO;
separate (Test_Print)
procedure Terminal (Message : String) is
begin
Ada.Text_IO.Put_Line(Ada.Text_IO.Current_Error, Message);
end Terminal;
with Ada.Streams.Stream_IO; use Ada.Streams;
with Unchecked_Conversion;
package body Print_Pak is
function To_Byte is new Unchecked_Conversion
(Source => Character,
Target => Stream_Element);
stdout : Stream_IO.File_Type;
procedure Print_Old (Item : String) is
subtype Index is Stream_Element_Offset range
Stream_Element_Offset(Item'First) ..
Stream_Element_Offset(Item'Last);
subtype XString is String (Item'Range);
subtype XBytes is Stream_Element_Array (Index);
function To_Bytes is new Unchecked_Conversion
(Source => XString,
Target => XBytes);
LF : constant Stream_Element_Array := (1 => To_Byte (ASCII.LF));
begin
Stream_IO.Write (stdout, To_Bytes (Item));
Stream_IO.Write (stdout, LF);
end Print_Old;
procedure Print (Item : String) is
subtype Index is Stream_Element_Offset range
Stream_Element_Offset(Item'First)
.. Stream_Element_Offset(Item'Last + 1);
subtype XString is String (Item'First .. Item'Last + 1);
subtype XBytes is Stream_Element_Array (Index);
function To_Bytes is new Unchecked_Conversion
(Source => XString,
Target => XBytes);
begin
Stream_IO.Write (stdout, To_Bytes (Item & ASCII.LF));
end Print;
begin
Stream_IO.Open (stdout,
Mode => Stream_IO.Out_File,
Name => "/dev/stdout");
end Print_Pak;
next prev parent reply other threads:[~2009-08-07 8:53 UTC|newest]
Thread overview: 116+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-01 12:21 Ada Shootout program for K-Nucleotide (patches) Georg Bauhaus
2009-08-01 12:59 ` Ludovic Brenta
2009-08-01 13:59 ` Georg Bauhaus
2009-08-01 13:50 ` Gautier write-only
2009-08-01 15:21 ` Ludovic Brenta
2009-08-01 15:37 ` Gautier write-only
2009-08-02 12:55 ` Georg Bauhaus
2009-08-27 11:17 ` Ole-Hjalmar Kristensen
2009-08-27 12:25 ` Georg Bauhaus
2009-09-01 8:06 ` Ole-Hjalmar Kristensen
2009-09-01 9:29 ` Georg Bauhaus
2009-09-01 10:48 ` Ole-Hjalmar Kristensen
2009-09-01 10:16 ` Ole-Hjalmar Kristensen
2009-09-01 11:34 ` Georg Bauhaus
2009-09-01 12:11 ` Ole-Hjalmar Kristensen
2009-09-01 14:36 ` Georg Bauhaus
2009-09-03 8:49 ` Ole-Hjalmar Kristensen
2009-09-02 8:44 ` Georg Bauhaus
2009-09-02 11:07 ` Ole-Hjalmar Kristensen
2009-09-03 8:13 ` Ole-Hjalmar Kristensen
2009-09-03 10:39 ` Georg Bauhaus
2009-08-03 8:56 ` Jacob Sparre Andersen
2009-08-03 11:43 ` Georg Bauhaus
2009-08-03 12:36 ` Jacob Sparre Andersen
2009-08-03 18:31 ` Isaac Gouy
2009-08-03 20:29 ` Robert A Duff
2009-08-04 15:43 ` Isaac Gouy
2009-08-04 16:06 ` Isaac Gouy
2009-08-04 17:08 ` Georg Bauhaus
2009-08-05 15:58 ` Isaac Gouy
2009-08-05 21:18 ` Georg Bauhaus
2009-08-05 22:04 ` Ludovic Brenta
2009-08-05 22:31 ` Georg Bauhaus
2009-08-05 23:44 ` Jeffrey R. Carter
2009-08-06 8:38 ` Georg Bauhaus
2009-08-06 21:39 ` Georg Bauhaus
2009-08-06 22:42 ` Jeffrey R. Carter
2009-08-07 8:53 ` Georg Bauhaus [this message]
2009-08-07 9:21 ` Jacob Sparre Andersen
2009-08-07 9:23 ` Jacob Sparre Andersen
2009-08-09 19:17 ` Georg Bauhaus
2009-08-13 20:56 ` jonathan
2009-08-13 21:30 ` jonathan
2009-08-13 22:08 ` Georg Bauhaus
2009-08-14 15:31 ` jonathan
2009-08-06 7:51 ` Dmitry A. Kazakov
2009-08-06 0:07 ` Isaac Gouy
2009-08-06 8:36 ` Georg Bauhaus
2009-08-06 9:09 ` Dmitry A. Kazakov
2009-08-06 10:34 ` Georg Bauhaus
2009-08-06 10:49 ` Dmitry A. Kazakov
2009-08-06 15:21 ` Isaac Gouy
2009-08-03 20:47 ` Ludovic Brenta
2009-08-01 17:07 ` jonathan
2009-08-01 17:59 ` jonathan
2009-08-02 11:39 ` Georg Bauhaus
2009-08-02 16:00 ` jonathan
2009-08-02 16:42 ` jonathan
2009-09-03 13:44 ` Olivier Scalbert
2009-09-03 14:08 ` Ludovic Brenta
2009-09-03 15:13 ` Olivier Scalbert
2009-09-03 19:11 ` sjw
2009-09-04 6:11 ` Olivier Scalbert
2009-09-04 8:18 ` Ludovic Brenta
2009-09-04 10:17 ` Olivier Scalbert
2009-09-04 12:37 ` Ludovic Brenta
2009-09-04 13:50 ` Olivier Scalbert
2009-09-04 12:50 ` Ludovic Brenta
2009-09-04 16:22 ` Georg Bauhaus
2009-09-04 16:29 ` Georg Bauhaus
2009-09-04 16:38 ` Ludovic Brenta
2009-09-04 17:58 ` Georg Bauhaus
2009-09-04 18:12 ` Georg Bauhaus
2009-09-05 20:16 ` Georg Bauhaus
2009-09-07 7:45 ` Olivier Scalbert
2009-09-07 9:19 ` Georg Bauhaus
2009-09-07 13:31 ` Olivier Scalbert
2009-09-07 14:38 ` jonathan
2009-09-07 15:03 ` Olivier Scalbert
2009-09-07 17:31 ` jonathan
2009-09-07 17:54 ` Olivier Scalbert
2009-09-07 18:07 ` Georg Bauhaus
2009-09-08 0:22 ` Georg Bauhaus
2009-09-04 17:56 ` Martin
2009-09-04 18:26 ` Georg Bauhaus
2009-09-04 21:51 ` Robert A Duff
2009-09-04 18:51 ` Ludovic Brenta
2009-09-04 9:27 ` Georg Bauhaus
2009-09-03 15:28 ` Georg Bauhaus
2009-09-04 1:24 ` Georg Bauhaus
2009-08-04 8:23 ` Martin
2009-08-16 15:20 ` jonathan
2009-08-17 15:46 ` Georg Bauhaus
2009-08-18 16:59 ` jonathan
2009-08-19 14:52 ` Georg Bauhaus
2009-08-19 16:40 ` Martin
2009-08-19 18:24 ` Robert A Duff
2009-08-19 22:15 ` jonathan
2009-08-19 23:50 ` Georg Bauhaus
2009-08-20 19:47 ` jonathan
2009-08-20 22:15 ` Georg Bauhaus
2009-08-21 21:43 ` jonathan
2009-08-22 22:35 ` Georg Bauhaus
2009-08-23 22:21 ` jonathan
2009-08-20 19:55 ` jonathan
2009-08-19 21:37 ` Georg Bauhaus
2009-08-19 19:22 ` jonathan
2009-08-19 19:27 ` jonathan
2009-08-27 9:05 ` Martin
2009-08-27 9:08 ` Martin
2009-08-27 10:01 ` Georg Bauhaus
2009-10-07 11:44 ` Olivier Scalbert
2009-10-07 12:04 ` Georg Bauhaus
2009-10-07 13:22 ` Martin
2009-10-07 14:15 ` Olivier Scalbert
2009-10-08 9:54 ` Georg Bauhaus
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox