Path: csiph.com!aioe.org!.POSTED!not-for-mail From: Rod Pemberton Newsgroups: comp.lang.forth Subject: Re: Ruby/Forth challenge for WJ Date: Wed, 13 Jan 2016 05:21:58 -0500 Organization: Aioe.org NNTP Server Lines: 176 Message-ID: <20160113052158.07176e0d@_> 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> 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-Notice: Filtered by postfilter v. 0.8.2 X-Newsreader: Claws Mail 3.13.1 (GTK+ 2.24.10; x86_64-unknown-linux-gnu) Xref: csiph.com comp.lang.forth:44819 On Tue, 12 Jan 2016 16:24:42 -0800 Paul Rubin wrote: > Paul Rubin writes: > >> with my 32 bit native code generating forth I get 983 ms on the > >> same laptop > > Interestingly, your 32 bit Forth is beating 64 bit C++ by a wide > > margin, even with C++ running on a considerably faster machine > > (i7-3770). > > Oh never mind, with optimization off and subscript checking on, I was > getting about 1 sec (GCC 4.7.2). With optimization -O3 and unsafe > subscripts, I get 141 ms. This is just for the counting part, not the > random initialization, which depends considerably on which PRNG you > use. The subscript checking actually only makes a tiny difference. > > ================================================================ > > #include > #include > #include > #include > #include > > const int Bufsize = 1<<28; > std::array buf; > > void init_array() > { > std::minstd_rand rd; > for (int i = 0; i < buf.size(); i += 3) > { > int r = rd(); > buf[i] = r&0xff; > r >>= 8; > buf[i+1] = r&0xff; > r >>= 8; > buf[i+2] = r&0xff; > } > } > > int main(int argc, char **argv) { > auto t0 = std::chrono::high_resolution_clock::now(); > init_array(); > auto t1 = std::chrono::high_resolution_clock::now(); > > static std::array counts; > for (uint8_t b: buf) { > ++counts[b]; > } > auto t2 = std::chrono::high_resolution_clock::now(); > std::chrono::duration d1 = t1 - t0; > std::chrono::duration d2 = t2 - t1; > std::cout << d1.count () << " " << d2.count() << std::endl; > return 0; > } Shouldn't r be unsigned? Why didn't you use 'unsigned char' for buf? I'm not familiar with C++, but I suspect 'i /* printf */ #include /* srand rand */ #include /* time clock_gettime */ #define CNT 256 #define BUF 268435456UL #define BIL 1000000000UL unsigned char buf[BUF+3]; void init_array(void) { int i,r; srand(time(0)); for(i=0;i>=8; buf[i+1]=r&0xff; r>>=8; buf[i+2]=r&0xff; } } int main(void) { unsigned int counts[CNT]; unsigned long i; struct timespec tim0,tim1,tim2; unsigned long long t0,t1,t2; /* memset */ for(i=0;i