From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fc89c,97188312486d4578 X-Google-Attributes: gidfc89c,public X-Google-Thread: 109fba,baaf5f793d03d420 X-Google-Attributes: gid109fba,public X-Google-Thread: 103376,97188312486d4578 X-Google-Attributes: gid103376,public X-Google-Thread: 1014db,6154de2e240de72a X-Google-Attributes: gid1014db,public From: James_Rogers Subject: Re: What's the best language to start with? [was: Re: Should I learn C or Pascal?] Date: 1996/08/15 Message-ID: <32134490.41C6@velveeta.apdev.cs.mci.com>#1/1 X-Deja-AN: 175003389 references: <4uaqqg$203@mulga.cs.mu.OZ.AU> <01bb8567$4adddbc0$87ee6fce@timpent.airshields.com> <4ue7tm$onn@solutions.solon.com> <01bb8608$9a12bc00$87ee6fce@timpent.airshields.com> <4ug10l$14p@solutions.solon.com> content-type: text/plain; charset=us-ascii organization: MCI Telecommunications Colorado Springs, CO mime-version: 1.0 newsgroups: comp.lang.c,comp.lang.c++,comp.unix.programmer,comp.lang.ada x-mailer: Mozilla 2.0 (X11; I; AIX 2) Date: 1996-08-15T00:00:00+00:00 List-Id: Peter Seebach wrote: > Tim Behrendsen wrote: >>>>int a[50000],b[50000],c[50000],d[50000],e[50000]; >>>>void test1() >>>>{ >>>> int i,j; >>>> for (j=0;j<10;++j){ >>>> for (i=0;i<50000;++i){ >>>> ++a[i];++b[i];++c[i];++d[i];++e[i]; >>>> } >>>> } >>>>} >>>>void test2() >>>>{ >>>> int i,j; >>>> for (j=0;j<10;++j){ >>>> for (i=0;i<50000;++i) ++a[i]; >>>> for (i=0;i<50000;++i) ++b[i]; >>>> for (i=0;i<50000;++i) ++c[i]; >>>> for (i=0;i<50000;++i) ++d[i]; >>>> for (i=0;i<50000;++i) ++e[i]; >>>> } >>>>} This example also behaves differently than predicted by Mr Behrendsen when implemented in Ada 95 using the GNAT compiler on a SPARC 20. I translated the above functions into Ada as follows: procedure test1 is begin for J in 1..10 loop for I in index_type loop a(I) := a(I) + 1; b(I) := b(I) + 1; c(I) := c(I) + 1; d(I) := d(I) + 1; e(I) := e(I) + 1; end loop; end loop; end test1; procedure test2 is begin for J in 1..10 loop for I in index_type loop a(I) := a(I) + 1; end loop; for I in index_type loop b(I) := b(I) + 1; end loop; for I in index_type loop c(I) := c(I) + 1; end loop; for I in index_type loop d(I) := d(I) + 1; end loop; for I in index_type loop e(I) := e(I) + 1; end loop; end loop; end test2; Each of the above loops was run 10 times. The timings are given below. The resulting timings with no optimization are: Test1 execution time: 12.2815 Test2 execution time: 16.0227 With full optimization and inlining of procedures the results are: Test1 execution time: 4.6333 Test2 execution time: 5.2464 Using Ada the performance is quite comperable to Mr Seebach's C results using gcc. The Ada results also do not support Mr Behrendsen's position. -- Jim Rogers ************************************************************* Celebrate Diplomacy