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=3.8 required=5.0 tests=BAYES_00,INVALID_MSGID, RATWARE_MS_HASH,RATWARE_OUTLOOK_NONAME 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: 1014db,6154de2e240de72a X-Google-Attributes: gid1014db,public X-Google-Thread: 103376,97188312486d4578 X-Google-Attributes: gid103376,public From: "Tim Behrendsen" Subject: Re: What's the best language to start with? [was: Re: Should I learn C or Pascal?] Date: 1996/08/17 Message-ID: <01bb8c91$be2409c0$87ee6fce@timpent.airshields.com>#1/1 X-Deja-AN: 174837639 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> <32134490.41C6@velveeta.apdev.cs.mci.com> content-type: text/plain; charset=ISO-8859-1 organization: A-SIS mime-version: 1.0 newsgroups: comp.lang.c,comp.lang.c++,comp.unix.programmer,comp.lang.ada Date: 1996-08-17T00:00:00+00:00 List-Id: James_Rogers wrote in article <32134490.41C6@velveeta.apdev.cs.mci.com>... > 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. My original timings where off by a factor of 10, BTW. The original implementation I ran used 100 for the outer loop, not 10. But this *is* interesting; that implies to me that the ADA compiler is not using pointer arithmetic when optimizing, and is calculating the indexes every time. This would make the overhead of the extra looping constructs overwhelm the gain in page locality. Just for some ADA to C performance comparison, it would be interesting to compile the C code on your SPARC 20 and see what the difference is. Since ADA has runtime array boundary checking, it makes we wonder if the optimizer is smart enough to know to get rid of the boundary checking when it's within a known loop like this. -- Tim Behrendsen (tim@airshields.com)