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: hook@cscsun3.larc.nasa.gov (Ed Hook) Subject: Re: What's the best language to start with? [was: Re: Should I learn C or Pascal?] Date: 1996/08/09 Message-ID: <4ufqlt$s71@reznor.larc.nasa.gov>#1/1 X-Deja-AN: 173171874 distribution: world references: <31FBC584.4188@ivic.qc.ca> <01bb83ad$29c3cfa0$87ee6fce@timpent.airshields.com> <4u89c4$p7p@solutions.solon.com> <01bb83f5$923391e0$87ee6fce@timpent.airshields.com> <4uah1k$b2o@solutions.solon.com> <01bb853b$ca4c8e00$87ee6fce@timpent.airshields.com> <4udjki$2l8@cnn.Princeton.EDU> organization: CSC/NASA Langley Research Center reply-to: hook@cscsun3.larc.nasa.gov newsgroups: comp.lang.c,comp.lang.c++,comp.unix.programmer,comp.lang.ada Date: 1996-08-09T00:00:00+00:00 List-Id: In article <4udjki$2l8@cnn.Princeton.EDU>, tim@franck (telnet user) writes: |> Tim Behrendsen (tim@airshields.com) wrote: |> |> : This is an interesting case, because it is somewhat inefficently |> : implemented. If you're interested in speed, you would do... |> |> : int gcd(int x, int y) { |> : int z; |> : while (y != 0) |> : z = y; y = x % y; x = z; |> : return(y); |> : } |> |> However if you are interested in correctness, you use braces for the |> loop. I think this case where you write assembly in C, get it wrong, |> and ... |> And ... if, in addition, you're interested in _mathematical_ correctness, you'll write instead: int gcd(int x, int y) { int z; while ( y != 0 ) { z = y; y = x % z; x = z; } return x; } On the other hand, I can greatly speed up tha given code; just replace it by int gcd(int x, int y) { return 0; } -- it does the same thing. |> : Using my AIX compiler, I get a nominal improvement of about |> : 10%, mostly because the speed of the modulo is much slower |> : than the inefficiency of recursion. |> |> only achieve a 10% speedup proves everyone else's point, and is an |> appropriate place to end this thread. |> I can't argue with that ... |> --------------------------------------------------------------------------- |> Tim Hollebeek | Disclaimer :=> Everything above is a true statement, |> Electron Psychologist | for sufficiently false values of true. |> Princeton University | email: tim@wfn-shop.princeton.edu |> ----------------------| http://wfn-shop.princeton.edu/~tim (NEW! IMPROVED!) -- Ed Hook | Coppula eam, se non posit Computer Sciences Corporation | acceptera jocularum. NASA Langley Research Center | Me? Speak for my employer?...<*snort*> Internet: hook@cscsun3.larc.nasa.gov | ... Get a _clue_ !!! ...