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=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109fba,baaf5f793d03d420 X-Google-Attributes: gid109fba,public X-Google-Thread: fc89c,97188312486d4578 X-Google-Attributes: gidfc89c,public X-Google-Thread: 1014db,6154de2e240de72a X-Google-Attributes: gid1014db,public X-Google-Thread: 103376,97188312486d4578 X-Google-Attributes: gid103376,public From: seebs@solutions.solon.com (Peter Seebach) Subject: Re: What's the best language to start with? [was: Re: Should I learn C or Pascal?] Date: 1996/08/12 Message-ID: <4unn8o$rkl@solutions.solon.com>#1/1 X-Deja-AN: 173721048 references: <31FBC584.4188@ivic.qc.ca> <01bb8534$b2718bc0$87ee6fce@timpent.airshields.com> <01bb87cf$97ae8e80$87ee6fce@timpent.airshields.com> organization: Usenet Fact Police (Undercover) reply-to: seebs@solon.com newsgroups: comp.lang.c,comp.lang.c++,comp.unix.programmer,comp.lang.ada Date: 1996-08-12T00:00:00+00:00 List-Id: 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%. >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. -s -- Peter Seebach - seebs@solon.com - Copyright 1996 - http://www.solon.com/~seebs Unix/C Wizard - send mail for help, or send money for consulting! The *other* C FAQ, the hacker FAQ, et al. See web page above. Unsolicited email (junk mail and ads) is unwelcome, and will be billed for.