Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Paul Rubin Newsgroups: comp.lang.forth Subject: Re: Ruby/Forth challenge for WJ Date: Tue, 12 Jan 2016 16:24:42 -0800 Organization: A noiseless patient Spider Lines: 51 Message-ID: <87oacqmilx.fsf@jester.gateway.pace.com> References: <35f4686c-f2c4-4ed8-9c46-2238645b9b97@googlegroups.com> <6e01edb6-e936-4418-bb77-e2ef9369a339@googlegroups.com> <87si22mj3x.fsf@jester.gateway.pace.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="89fc4f87faf042e7e4d428a3639a51e3"; logging-data="23471"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18P5mgrXZlziUhTHTy0FpKc" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:1MiMXKQWMEm+ULH8xHge01bKYTw= sha1:8mK+qzYTw14+Xyajiky/k7eNvoM= Xref: csiph.com comp.lang.forth:44808 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; }