--#!/bin/bush

-- Running in BUSH will require:
--pragma ada_95;

-- Compiling with Gnat will require:
with Ada.Text_IO,
     Ada.Integer_Text_IO,
     Ada.Long_Float_Text_IO,
     Ada.Strings.Unbounded.Text_IO;
use  Ada.Text_IO,
     Ada.Integer_Text_IO,
     Ada.Long_Float_Text_IO,
     Ada.Strings.Unbounded,
     Ada.Strings.Unbounded.Text_IO;

procedure benchmark is
  grand_total  : integer := 0;
  total1 : integer := 0;
  total2 : integer := 0;
  total3 : integer := 0;
  number : integer;
  f      : file_type;
begin

  -- this is the original code to generate the test data
  --create( f, out_file, "benchdata.txt" );
  --for i in 1..1000 loop
  --    put_line( f, numerics.truncation( ( numerics.random * 3 ) mod 3 + 1) );
  --end loop;
  --close( f );

  open( f, in_file, "benchdata.txt" );
  while not end_of_file( f ) loop
     -- Compiling with Gnat
     number := integer'value( to_string( get_line( f ) ) );
     -- Running in Bush
     --number := get_line( f );
     if number = 1 then
        total1 := total1 + 1;
     elsif number = 2 then
        total2 := total2 + 1;
     elsif number = 3 then
        total3 := total3 + 1;
     else
        put_line( standard_error, "Unexpected value" );
     end if;
     grand_total := grand_total + number;
  end loop;
  put( "Number of values: " );
  put( integer( line( f )-1 ) );
  new_line;
  put( "Total of 1s is:" );
  put( total1 );
  new_line;
  put( "Total of 2s is:" );
  put( total2 );
  new_line;
  put( "Total of 3s is:" );
  put( total3 );
  new_line;
  put( "Mean for the numbers is" );
  put( long_float( grand_total ) / long_float( line( f )-1 ) );
  new_line;
  close( f );
end benchmark;

