Path: csiph.com!aioe.org!.POSTED!not-for-mail From: Rod Pemberton Newsgroups: comp.lang.forth Subject: Re: Ruby/Forth challenge for WJ Date: Thu, 14 Jan 2016 01:37:46 -0500 Organization: Aioe.org NNTP Server Lines: 41 Message-ID: <20160114013746.71f8991c@_> References: <35f4686c-f2c4-4ed8-9c46-2238645b9b97@googlegroups.com> <6e01edb6-e936-4418-bb77-e2ef9369a339@googlegroups.com> <87si22mj3x.fsf@jester.gateway.pace.com> <87oacqmilx.fsf@jester.gateway.pace.com> <20160113052158.07176e0d@_> <8760yxuy6a.fsf@nightsong.com> NNTP-Posting-Host: n4wpt9zq8xR26Ttf9mo2BA.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org X-Newsreader: Claws Mail 3.13.1 (GTK+ 2.24.10; x86_64-unknown-linux-gnu) X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.forth:44861 On Wed, 13 Jan 2016 10:33:33 -0800 Paul Rubin wrote: > I put printf("%d\n", counts[23]) at the end of your C version, and > that gave: > > 0.673343 0.141221 > > it took 0.000000 without the extra print because the compiler saw that > counts (a local array in your version) was unused after being set. > The C++ version had counts as a global, so my guess is the compiler > presumed that some other module might use it. So, a few results without the optimized away loop: 1.006349 0.398377 1.035722 0.373584 1.026238 0.368511 0.964631 0.400756 Restructuring init_array() to not use shifts, but using a pointer to char for direct byte reads, didn't seem to help any. Results hovered around the same values. Maybe, computing a long-term result would slightly favor one method over the other. I didn't compare source via gcc -S. One is likely to produce fewer instructions. I also considered calling rand() more frequently to eliminate shifts, but I didn't test that. I presumed that rand() takes longer than the shifts. FYI, those results are for: 3.2Ghz AMD Phenom II X2 555 (dual core) 64-bit VLocity Linux (VectorLinux) GCC 4.7.2 Rod Pemberton