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: 103376,97188312486d4578 X-Google-Attributes: gid103376,public X-Google-Thread: 1014db,6154de2e240de72a X-Google-Attributes: gid1014db,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/13 Message-ID: <01bb88d6$fe8aaaa0$32ee6fce@timhome2>#1/1 X-Deja-AN: 174039891 references: <31FBC584.4188@ivic.qc.ca> <01bb8534$b2718bc0$87ee6fce@timpent.airshields.com> <01bb87cf$97ae8e80$87ee6fce@timpent.airshields.com> <4unn8o$rkl@solutions.solon.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-13T00:00:00+00:00 List-Id: Peter Seebach wrote in article <4unn8o$rkl@solutions.solon.com>... > In article <01bb87cf$97ae8e80$87ee6fce@timpent.airshields.com>, > 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]; > >> > } > >> >} > > >Show me the computer where test1 comes out faster. > > gcc/SPARC, with *NO* optimization. test1 runs 10 times in 15.66 seconds, > test2 takes 22.02 seconds. > > With optimization, test2 comes out faster on that compiler. > > In other words, which is faster depends on the compiler. And on context. > > >Not gonna find this mythical bizarre beast, except for trivial > >differences because of the extra loop overhead. > > Trivial, like a factor of 50%. I suspect that no optimization is not using pointers/registers. Try rewriting the subroutines to use pointers both ways and then try it with no optimization. > >Again, is it the case that I can order my code into any > >algorithmically valid sequence and get identical running times? > > No. However, it is the case that the differences simply don't justify the > overhead. I see the "faster" version as having more code, and no real reason > for it. The pithy 10% advantage it has when it's better does not justify the > 50% disadvantage it has when it's worse. On my systems. Only 10% on SPARC? Crummy paging architecture. -- Tim Behrendsen (tim@airshields.com)