comp.lang.ada
 help / color / mirror / Atom feed
From: Mark  McKinney <mckmark@mail.concentric.net>
Subject: Re: C is 'better' than Ada because...
Date: 1996/08/02
Date: 1996-08-02T00:00:00+00:00	[thread overview]
Message-ID: <4tu2gd$rt8@herald.concentric.net> (raw)
In-Reply-To: Pine.A32.3.91.960801090756.64586H-100000@wc.airshields.com


"Let the compiler do the optimization ?"
Someone said try it so I did.           
           
Background :  To say that only c does pointer arithmetic 
and Ada does not is not entirely accurate. I wrote a bubble sort using 3 
slightly different techniques. THe second closely resembles c pointer 
arithmetic. Except it should calculate the offset from the original address 
instead of accumulating it. Possible at the expense of a multiply opertion. 
Not used by the c method. 

The concept : Use a simple algorithym use arrays and try to optimize it in 
Ada. Compare the unoptimized results with the optimized results. See which is 
better for the compilers I have access to.

The Test : I chose a bubble sort because it has nested loops so that elements 
of the array would be used over and over. It uses Two different array offsets 
and the swap repeats them.

The Methods : Sort 1 is the standard way of using arrays. Sort 2 attempts 
to use an address clause to eliminat redundant use of array offsets. 
Sort 3 uses a renames clause to for the same purpose. 

The expectation : Sort 2 and Sort 3 should perform better than sort 1 when 
no optimization is used. The results are unpredictble with optimization 
but they should be faster when optimized as well.


The Loops: 
Sort 1 The standard way.

   -- I expect that for each array reference. 
   -- The offset must be recalculated.        
   -- There are Six potential Calculationsbut 
   -- only two are needed.The optimizer should  
   -- use extract common expressions if used. 

   for INDEX_1 in BIG_ARRAY'RANGE loop
      for INDEX_2 in INDEX_1 .. BIG_ARRAY'LAST loop
         if BIG_ARRAY(INDEX_2) < BIG_ARRAY(INDEX_1) then  
            -- Swap                                       
            TMP := BIG_ARRAY(INDEX_1);                    
            BIG_ARRAY(INDEX_1) := BIG_ARRAY(INDEX_2);      
            BIG_ARRAY(INDEX_2) := TMP;                    
         end if;
      end loop;
   end loop;

Sort 2 Declare an Addres clause.
   for INDEX_1 in BIG_ARRAY'RANGE loop
      for INDEX_2 in INDEX_1 .. BIG_ARRAY'LAST loop  
         -- This technique should force the compiler to use one calculation
         -- for each of the two references. 
         declare                                            
            LOW_ADR : constant SYSTEM.ADDRESS := BIG_ARRAY(INDEX_1)'ADDRESS;                         
                  
            LOW_INT : INTEGER;
            for LOW_INT use at LOW_ADR;     -- This is roughly equivelent to poiter arithmetic.

            HI_ADR : constant SYSTEM.ADDRESS := BIG_ARRAY(INDEX_2)'ADDRESS;                          
                 
            HI_INT  : INTEGER;
            for HI_INT use at HI_ADR;
         begin
            if HI_INT < LOW_INT then        -- This is easier to read.
               -- Swap
               TMP := LOW_INT;
               LOW_INT := HI_INT;
               HI_INT := TMP;
            end if;
         end;
      end loop;
   end loop;
           
Sort 3 Use a renames clause.
   for INDEX_1 in BIG_ARRAY'RANGE loop
      for INDEX_2 in INDEX_1 .. BIG_ARRAY'LAST loop
         -- This method only gives the compiler a hint.
         -- The compiler could treat this only as a macro though.
         declare
            LOW_INT : INTEGER renames BIG_ARRAY(INDEX_1);   
            HI_INT  : INTEGER renames BIG_ARRAY(INDEX_2);   
         begin
            if HI_INT < LOW_INT then        -- This is also easier to read.
               -- Swap
               TMP := LOW_INT;
               LOW_INT := HI_INT;
               HI_INT := TMP;
            end if;
         end;
      end loop;
   end loop;


The results :
   All compilations retained expception handling (error_checking).
   Execution times for various compilers.
                  
                            ------ Unoptimized --------   ------ Optimized  --------- 
Compiler                    Sort 1    Sort 2   Sort 3     Sort 1   Sort 2    Sort 3   
                            _________ ________ ________   ________ ________  ________ 
ALSYS DOS (90MHZPENTIUM)      27.8472  19.7731  19.2239    13.5117  19.7731   15.3242 
ALSYS HP 755 (PA-RISC)        37.0996  29.0010  28.9375    21.8467  28.9854   23.8672 
Verdix 3b2                  1417.0000 984.0000 782.0000   815.0000 606.0000  487.0000 
Gnat WIN95/NT(90MHzPentium)   28.9500  27.7400  26.9700     8.0200   6.9200    6.9200 
ALSYS(WIN32)(90MHzPentium)    29.0600  21.6900  21.1500    15.2200  24.6600   24.9300 

   
   Best optimizer show optimization on Sort 1
   Best method shows the most effective combination of sort and optimization for a compiler. 
   
                                  -------- Best -------                                        
                                  Optimizer      Method                                        
                                  _________    _________                                       
ALSYS DOS (90MHZPENTIUM)          206.0973%    206.0973%  Let the optomizer Do it              
ALSYS HP 755 (PA-RISC)            169.8181%    169.8181%  Let the optomizer Do it              
Verdix 3b2                        173.8650%    290.9651%  Combination (Optimizer + Sort 3)     
Gnat WIN95/NT(90MHzPentium)       360.9726%    418.3526%  Combination (Optimizer + Sort 2 or 3)
ALSYS(WIN32)(90MHzPentium)        190.9326%    190.9326%  Let the optomizer Do it              
                              

Conclusion :
   If highest performance is a requirement for a routine. Try and test differnt techniques. 
   I suspect this applies in any programming language. Idealy you should pick a compiler that 
   meets this requirement. Different implementations of a language can have different results. 
   Use a test that meets your requirements.(Event though the pentium machine outperforms the HP in
   this test text reports genrated off of flat files in both C and Ada are about 60 times as 
   fast on the HP as The Pentium Better Io?)
   The "I'll be sure and code it in assembly" argument has merit when justified by requirements. 
   I you care about performance find many compilers and test them on the target platform. 
   
Surprizes :
   In the case of the ALSYS compilers it is clearly better to let the optimizer do the work.
   GNAT Did exceptionally well. (I haven't used it much I'll use it more, if Someone can help 
   me get the Windows API to compile correctly)    

Comments :
   A better optimization would be to use a better sorting algorithym. Generally this should 
   be tried first.
   
   There is no substitute for hard work if you really want to know.

   These test results are not intended to endorse any particular product. The test 
   were done hastily and in less than Ideal conditions. Let your system requirements 
   determine which compiler you choose using appropriate test cases.

   Any opinion are mine and mine alone.
   All other disclaimers apply.
   
   If you want complete source I'll send it. 
   send requests to mckmark@mail.concentric.net

             Mark McKinney







  parent reply	other threads:[~1996-08-02  0:00 UTC|newest]

Thread overview: 239+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-08-01  0:00 C is 'better' than Ada because Tim Behrendsen
1996-08-02  0:00 ` David Bonham
1996-08-02  0:00 ` Mark McKinney [this message]
     [not found] ` <9608061851.AA17508@camo.brc.shell.com>
1996-08-06  0:00   ` Tim Behrendsen
     [not found] <Pine.GSO.>
     [not found] ` <4 <4vb399$kt8@mtinsc01-mgt.ops.worldnet.att.net>
1996-08-20  0:00   ` Adam Beneschan
1996-08-20  0:00     ` Craig Franck
1996-08-21  0:00     ` Mike Roske
1996-08-21  0:00       ` William  C Brennan
  -- strict thread matches above, loose matches on Subject: below --
1996-08-04  0:00 @#$%!?!
1996-08-01  0:00 William Clodius
1996-08-03  0:00 ` Tim Behrendsen
1996-08-05  0:00   ` Kevin D. Quitt
1996-08-05  0:00 ` Stefan 'Stetson' Skoglund
1996-08-05  0:00 ` William Clodius
1996-07-30  0:00 Spasmo
     [not found] ` <01bb7e29$61e3d260$87ee6fce@timpent.airshields.com>
1996-07-31  0:00   ` Bob Kitzberger
1996-07-31  0:00     ` Tim Behrendsen
1996-07-31  0:00 ` Jon S Anthony
1996-08-01  0:00   ` Tim Behrendsen
1996-08-02  0:00     ` Ralph Silverman
1996-06-19  0:00 Alan Brain
1996-06-20  0:00 ` Ron Thompson
1996-06-22  0:00 ` Nasser Abbasi
1996-06-22  0:00   ` David Morton
1996-06-22  0:00     ` Robert Dewar
1996-06-23  0:00       ` The Deviant
1996-06-23  0:00         ` John Winters
1996-06-23  0:00         ` Michael Feldman
1996-06-23  0:00         ` Robert Dewar
1996-06-24  0:00         ` token%/etc/HOSTNAME
1996-06-23  0:00     ` John Winters
1996-06-23  0:00       ` David Morton
1996-06-23  0:00         ` Lawrence Kirby
1996-06-23  0:00         ` John Winters
1996-06-23  0:00           ` David Morton
1996-06-30  0:00   ` Nasser Abbasi
1996-06-23  0:00 ` Nasser Abbasi
1996-06-23  0:00   ` Fergus Henderson
1996-06-23  0:00     ` Robert Dewar
1996-06-28  0:00       ` Fergus Henderson
     [not found] ` <874508446wnr@t-cubed.demon.co.uk>
1996-06-29  0:00   ` Jon S Anthony
1996-06-29  0:00 ` Kevin D. Quitt
1996-06-29  0:00   ` Robert Dewar
1996-06-30  0:00   ` Fergus Henderson
1996-07-01  0:00     ` Mike Roske
1996-07-01  0:00       ` Robert Dewar
1996-07-02  0:00       ` Ken Garlington
1996-07-03  0:00     ` Kevin D. Quitt
1996-07-04  0:00       ` Ian Ward
1996-07-05  0:00         ` Peter Amey
1996-07-05  0:00           ` Robert Dewar
1996-07-10  0:00             ` James A. Squire
1996-07-15  0:00               ` Oliver Kellogg
1996-07-16  0:00                 ` Oliver Kellogg
1996-07-18  0:00                   ` Fraser Wilson
1996-07-18  0:00                     ` Fergus Henderson
1996-07-19  0:00                   ` Keith Thompson
1996-07-17  0:00                 ` Robert Dewar
1996-07-11  0:00             ` James A. Squire
1996-07-16  0:00             ` Nasser Abbasi
1996-07-16  0:00               ` Mark A Biggar
1996-07-17  0:00             ` James A. Squire
1996-07-17  0:00             ` Laurent Guerby
1996-07-17  0:00               ` David Emery
1996-07-18  0:00             ` James A. Squire
1996-07-07  0:00           ` Kevin D. Quitt
1996-07-08  0:00             ` Ian Ward
1996-07-08  0:00               ` C is 'better' than Ada ... NOT!! Kevin D. Quitt
1996-07-12  0:00                 ` C is 'better' than Ada because John F. Bode
1996-07-15  0:00                   ` Sandy McPherson
1996-07-18  0:00                     ` Robert Dewar
1996-07-19  0:00                       ` Theodore E. Dennison
1996-07-19  0:00                     ` Theodore E. Dennison
1996-07-19  0:00                     ` Ken Garlington
1996-07-20  0:00                       ` Michael Feldman
1996-07-21  0:00                         ` Alfonso Urdaneta
1996-07-21  0:00                           ` Robert Dewar
1996-07-22  0:00                             ` Kevin D. Quitt
1996-07-22  0:00                               ` Robert Dewar
1996-07-26  0:00                               ` Richard Riehle
     [not found]                             ` <31f3c52e.238719470 <Pine.GSO.3.92.960726122347.25896E-100000@nunic.nu.edu>
1996-07-31  0:00                               ` Darrin Smith
1996-07-31  0:00                                 ` Fergus Henderson
1996-08-01  0:00                                 ` Jerry van Dijk
1996-08-06  0:00                                   ` Kirk Bradley
1996-08-09  0:00                                   ` Richard Riehle
1996-08-10  0:00                                     ` Craig Franck
1996-08-16  0:00                                       ` Richard Riehle
1996-08-18  0:00                                         ` Craig Franck
     [not found]                                       ` <Pine.GSO.3.92.960816102000. <4v5pis$4h1@mtinsc01-mgt.ops.worldnet.att.net>
1996-08-18  0:00                                         ` David Weller
1996-08-15  0:00                                     ` Mike Stark
1996-08-02  0:00                                 ` Robert Dewar
1996-08-11  0:00                             ` Jon S Anthony
     [not found]                             ` <31f3c52e.238719470 <4uj42h$j06@mtinsc01-mgt.ops.worldnet.att.net>
1996-08-11  0:00                               ` Doug & Rose Miller
1996-08-11  0:00                                 ` Craig Franck
1996-08-11  0:00                                   ` Doug & Rose Miller
1996-08-12  0:00                                     ` Craig Franck
1996-08-16  0:00                                       ` nasser
     [not found]                             ` <31f3c52e.238719470 <4v5pis$4h1@mtinsc01-mgt.ops.worldnet.att.net>
1996-08-18  0:00                               ` Doug & Rose Miller
1996-08-20  0:00                                 ` Craig Franck
1996-07-23  0:00                         ` Ken Garlington
1996-07-27  0:00                       ` Tim Behrendsen
1996-07-27  0:00                         ` Lawrence Kirby
1996-07-29  0:00                         ` Ian Ward
1996-07-30  0:00                         ` Bob Cousins
1996-07-30  0:00                           ` Robert Dewar
1996-09-05  0:00                             ` Bob Cousins
1996-08-13  0:00                       ` Jon S Anthony
1996-08-14  0:00                         ` Craig Franck
1996-08-28  0:00                           ` Van Snyder
1996-08-14  0:00                       ` Jon S Anthony
1996-08-15  0:00                         ` Craig Franck
1996-08-15  0:00                           ` Joe Gwinn
1996-08-16  0:00                             ` Don Nelson
1996-08-19  0:00                               ` Joe Gwinn
1996-08-19  0:00                                 ` Ken Garlington
1996-08-28  0:00                         ` Van Snyder
1996-08-30  0:00                           ` Norman H. Cohen
1996-08-15  0:00                       ` Jon S Anthony
1996-08-20  0:00                         ` nasser
1996-08-15  0:00                       ` Stefan 'Stetson' Skoglund
1996-08-15  0:00                     ` David Weller
1996-08-15  0:00                       ` William  C Brennan
1996-07-18  0:00               ` Hamilton Link
1996-07-19  0:00                 ` Kevin D. Quitt
1996-07-08  0:00             ` Robert Dewar
1996-07-10  0:00               ` Peter Hermann
1996-07-15  0:00                 ` Tim McGuire
1996-07-16  0:00                   ` Kevin D. Quitt
1996-07-16  0:00                     ` Robert Dewar
1996-07-18  0:00                     ` Ken Garlington
1996-07-19  0:00                       ` Kevin D. Quitt
1996-07-19  0:00                         ` Richard O'Rourke
1996-07-22  0:00                           ` Kevin D. Quitt
1996-07-22  0:00                             ` Robert Dewar
1996-07-23  0:00                               ` Tim Behrendsen
1996-07-24  0:00                                 ` Dirk Dickmanns
1996-07-24  0:00                                 ` Theodore E. Dennison
1996-07-27  0:00                                   ` Tim Behrendsen
1996-07-29  0:00                                     ` Bob Kitzberger
1996-07-30  0:00                                       ` Tim Behrendsen
1996-07-30  0:00                                         ` Theodore E. Dennison
1996-07-30  0:00                                         ` Richard A. O'Keefe
1996-07-30  0:00                                           ` Tim Behrendsen
1996-07-29  0:00                                     ` Dirk Dickmanns
1996-07-30  0:00                                       ` Tim Behrendsen
1996-07-31  0:00                                         ` Dirk Dickmanns
1996-07-31  0:00                                           ` Kevin D. Quitt
1996-08-01  0:00                                             ` Alan Brain
1996-08-02  0:00                                               ` Kevin D. Quitt
1996-08-05  0:00                                                 ` Byron B. Kauffman
1996-08-15  0:00                                               ` Mike Roske
1996-08-15  0:00                                                 ` David Shochat
1996-08-16  0:00                                                   ` Ken Garlington
1996-08-16  0:00                                                 ` John Herro
1996-08-16  0:00                                                   ` John Herro
1996-08-16  0:00                                                 ` Jon S Anthony
1996-08-05  0:00                                             ` Robb Nebbe
1996-08-02  0:00                                           ` Dirk Dickmanns
1996-07-31  0:00                                         ` whiting_ms@corning.com (Matt Whiting)
1996-07-30  0:00                                     ` Theodore E. Dennison
1996-07-29  0:00                                   ` system
1996-07-30  0:00                                     ` Tim Behrendsen
1996-07-24  0:00                                 ` JamesS1889
1996-07-25  0:00                                 ` Alan Brain
1996-07-23  0:00                               ` Kevin D. Quitt
1996-07-24  0:00                                 ` Theodore E. Dennison
1996-07-24  0:00                                   ` Kevin D. Quitt
1996-07-25  0:00                                     ` Alan Brain
1996-07-25  0:00                                     ` Steve Howard
1996-07-27  0:00                                     ` Bob Kitzberger
1996-07-26  0:00                                   ` Mike Roske
1996-07-25  0:00                                 ` Fergus Henderson
1996-07-25  0:00                                   ` Kevin D. Quitt
1996-07-26  0:00                                     ` Fergus Henderson
1996-07-26  0:00                                     ` kennedy1
1996-07-23  0:00                               ` Theodore E. Dennison
1996-07-18  0:00                     ` Bob Gilbert
1996-07-19  0:00                       ` Kevin D. Quitt
1996-07-10  0:00               ` John F. Bode
1996-07-11  0:00                 ` Mike Roske
     [not found]               ` <4rvr2j$2gb0@info4.rus.uni-s <nhn30yhw6t.fsf@paralysys>
1996-07-18  0:00                 ` Robert Dewar
1996-07-18  0:00                 ` Kevin D. Quitt
1996-07-26  0:00                 ` Richard Riehle
1996-07-10  0:00             ` Stephen M O'Shaughnessy
1996-07-10  0:00               ` Peter Seebach
1996-07-18  0:00             ` Brian Rogoff
1996-07-19  0:00             ` James A. Squire
1996-07-29  0:00             ` William Clodius
1996-07-30  0:00               ` Richard A. O'Keefe
1996-07-30  0:00                 ` Tim Behrendsen
1996-08-01  0:00                   ` Byron B. Kauffman
1996-08-01  0:00                     ` Ian Ward
1996-07-30  0:00               ` Robert Dewar
1996-07-31  0:00                 ` Tim Behrendsen
     [not found]                   ` <9608020139.AA29105@pulsar.telesoft>
1996-08-02  0:00                     ` Tim Behrendsen
1996-08-05  0:00                       ` Kevin D. Quitt
1996-07-31  0:00               ` Ralph Silverman
1996-07-30  0:00             ` Robert I. Eachus
1996-08-01  0:00               ` David Wheeler
1996-07-30  0:00             ` William Clodius
1996-08-01  0:00               ` Tim Behrendsen
1996-08-01  0:00             ` Olivier Devuns @pulsar
1996-08-11  0:00             ` Jon S Anthony
1996-08-12  0:00               ` Craig Franck
1996-08-12  0:00                 ` John Howard
1996-08-13  0:00                   ` Craig Franck
1996-08-13  0:00                     ` Ken Garlington
1996-08-14  0:00                       ` Craig Franck
1996-08-12  0:00                 ` James A. Squire
1996-08-12  0:00                   ` Craig Franck
1996-08-14  0:00                 ` Stephen M O'Shaughnessy
1996-08-14  0:00                 ` Stephen M O'Shaughnessy
     [not found]                 ` <Pine.GS <gwinn-1908961215100001@smc19.ed.ray.com>
1996-08-19  0:00                   ` Adam Beneschan
1996-08-13  0:00             ` Jon S Anthony
1996-08-13  0:00             ` Jon S Anthony
1996-08-14  0:00             ` Norman H. Cohen
1996-08-19  0:00             ` Jon S Anthony
1996-08-20  0:00               ` Craig Franck
1996-08-20  0:00             ` Jon S Anthony
1996-08-21  0:00               ` Craig Franck
1996-08-27  0:00             ` Valentin Bonnard
1996-07-06  0:00         ` Walter B. Hollman Sr.
1996-07-05  0:00       ` Jon S Anthony
1996-07-08  0:00         ` Peter Hermann
1996-07-09  0:00           ` Dirk Dickmanns
1996-07-12  0:00       ` ntxbow
1996-07-15  0:00         ` Kevin D. Quitt
1996-07-15  0:00           ` Robert Dewar
1996-07-16  0:00           ` Ian Ward
1996-07-17  0:00             ` Dale Stanbrough
1996-07-23  0:00       ` Jon S Anthony
1996-07-29  0:00       ` William Clodius
1996-07-31  0:00       ` Darin Johnson
1996-08-01  0:00         ` Tim Behrendsen
1996-08-01  0:00       ` Jon S Anthony
1996-08-01  0:00       ` Jon S Anthony
1996-08-05  0:00       ` Stefan 'Stetson' Skoglund
1996-08-16  0:00       ` Jon S Anthony
1996-07-01  0:00 ` James A. Squire
1996-07-02  0:00 ` Darin Johnson
replies disabled

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