Path: csiph.com!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 14:34:26 -0800 Organization: A noiseless patient Spider Lines: 32 Message-ID: <87y4bumnpp.fsf@jester.gateway.pace.com> References: <35f4686c-f2c4-4ed8-9c46-2238645b9b97@googlegroups.com> <65ba1513-cfa4-4ebe-9583-4729f4b0815a@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="89fc4f87faf042e7e4d428a3639a51e3"; logging-data="30501"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+YCAdZVNVLeXaj7z/Ro9v9" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:ZrXrg0YZVdpPjypIKKJtxLwGNmE= sha1:/sllORPfORsmhPTl/UFL6C/dDuc= Xref: csiph.com comp.lang.forth:44800 Chris Curl writes: > Since Ruby is so much better than the "toy" language Forth, Ruby can > do the same thing be much faster than 600ms, right? Just for laughs, I tried it in Python for 1MB instead of 256MB. The random initialization phase took 0.743 sec and the counting phase took 0.009 sec, scaling to about 23 sec for counting 256MB. The random initialization was pretty inefficient so I wouldn't count it despite not seeing an obvious faster way. The counting phase was the quickest obvious way I could think of offhand, though maybe there is something better. The code is: from random import randrange import time import array import itertools def main(): t0 = time.time() vec = bytearray(itertools.islice( iter(lambda: randrange(0,255), None), 2**20 ) ) t1 = time.time() u = array.array('i',[0]*256) for c in vec: u[c] += 1 t2 = time.time() print t1-t0, t2-t1 main()