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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,703c4f68db81387d X-Google-Thread: 115aec,703c4f68db81387d X-Google-Attributes: gid103376,gid115aec,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!newshub.sdsu.edu!tethys.csu.net!nntp.csufresno.edu!sn-xit-03!sn-xit-11!sn-xit-08!sn-post-01!supernews.com!corp.supernews.com!not-for-mail From: CTips Newsgroups: comp.lang.ada,comp.realtime Subject: Re: 10 rules for benchmarking (was Re: Teaching new tricks to an old dog (C++ -->Ada)) Date: Sat, 12 Mar 2005 23:10:24 -0500 Organization: Posted via Supernews, http://www.supernews.com Message-ID: <1137falp86qhk89@corp.supernews.com> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041217 X-Accept-Language: en-us, en MIME-Version: 1.0 References: <4229bad9$0$1019$afc38c87@news.optusnet.com.au> <1110052142.832650@athnrd02> <1110284070.410136.205090@o13g2000cwo.googlegroups.com> <395uqaF5rhu2mU1@individual.net> <112rs0bdr2aftdf@corp.supernews.com> <1inxxr988rxgg$.1w9dedak41k89.dlg@40tude.net> <112s1r0rf0o8nca@corp.supernews.com> <112sonip5v4dca6@corp.supernews.com> <112t3de6fu04f38@corp.supernews.com> <1110396477.596174.285520@o13g2000cwo.googlegroups.com> <112vb2t8eonuhed@corp.supernews.com> <1110422108.925127.54110@o13g2000cwo.googlegroups.com> <11329cb96h2p19f@corp.supernews.com> <113394jjvppao64@corp.supernews.com> <1133s3qnmqmbjfb@corp.supernews.com> <4232a9f7$0$26552$9b4e6d93@newsread4.arcor-online.net> <11369p5jrcc6835@corp.supernews.com> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@supernews.com Xref: g2news1.google.com comp.lang.ada:9287 comp.realtime:1406 Date: 2005-03-12T23:10:24-05:00 List-Id: Jim Rogers wrote: > CTips wrote in news:11369p5jrcc6835@corp.supernews.com: > > >>Oh, and just to illustrate another point about Ada, try running the Ada >>program equivalent to the following program: >> >>#define N 30000 >>#define N2 60000 >> >>void >>setup_array( >> int * x[N2], >> int p[N+1], >> int q[N+1] >> ) >>{ >> int i; >> for( i = 0; i < N; i++ ) { >> x[i] = &p[i]; >> x[i+N] = &q[i]; >> >> } >>} > > > The function setup_array sets up the x array > so that the first N elements each individually > point to the elements of the p array, except for > the last element in the p array. The second N > elements of X point to the elements of the q > array, except for the last element of the q > array. > > >>void >>do_array( >> int * x[N2] >> ) >>{ >> int i; >> int *p; >> for( i = 0; i < N2; i++ ) { >> p = x[i]; >> p[1] = i; >> } >>} > > > do_array has p point to the ith element in x, > then treats p as an array and assigns its second > element the value i. > > This sort of programming is generally foolishness. This is meant to bring a performance issue into sharp focus. Each element of this program was picked specifically for that reason. Try writing the *equivalent* Ada program and *benchmark* it. See what the performance will be. The following elements are involved: - I want an array of "handles"; that's why I picked a set of pointers. - I want an array bounds check. Thats why the pointers are pointers to unbounded arrays, and why there is a p[1]. - I want the arrays to have a particular size; that is why I picked N as 30000. - I used two arrays p & q to inhibit a possible compiler optimization (which is not very likely, but its nice to cover all the bases) The rest of setup_array and main are really there to make sure that the right things happens, and that the function gets called the right number of times. This is not intended to be a real program; it is meant to illustrate how much slower Ada can get than C. Try and write it as specified and measure the resulting performance.