Path: csiph.com!news.mixmin.net!news.albasani.net!.POSTED!not-for-mail From: Melzzzzz Newsgroups: comp.lang.forth Subject: Re: Ruby/Forth challenge for WJ Date: Fri, 15 Jan 2016 06:55:00 +0100 Organization: albasani.net Lines: 69 Message-ID: <20160115065500.3d7bc73c@maxa-pc> References: <35f4686c-f2c4-4ed8-9c46-2238645b9b97@googlegroups.com> <87io2vu49p.fsf@nightsong.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Trace: news.albasani.net R9x+3Zx5qmOPyjldcjw1ue9N0K14xM8u2WUQi7sZVBqYpdgPM+41jam7YeVpDC/oehY3Y0kYY9fUXkEW/v589Q== NNTP-Posting-Date: Fri, 15 Jan 2016 05:55:00 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="GCFAyY908ivX7jpDiUMlHwp5X0Vkk6QP/JSjlIFsnthFIdXsH44aXDwgqvtf3sM3wPpOH80Ya6vV9gf8asSAGfJrkWDU8EOpsqT7HZfPzK7L0TybJ//ZcCiwLDruXdiT"; mail-complaints-to="abuse@albasani.net" X-Newsreader: Claws Mail 3.13.1 (GTK+ 2.24.29; x86_64-unknown-linux-gnu) Cancel-Lock: sha1:QSyXwju19YqgP7FafoCtG5Sxu8g= Xref: csiph.com comp.lang.forth:44889 On Thu, 14 Jan 2016 15:31:46 -0800 Paul Rubin wrote: > "WJ" writes: > > Here's an OCaml version... let size = 99_000_000 ;; ... > > ==== Output: (on an old winXP computer) ==== > > Array filled in 2.953 seconds. > > Bytes counted in 0.266 seconds. > > On i7-3770: > Array filled in 3.808 seconds. > Bytes counted in 0.220 seconds. > > With size changed to 256MiB: > Array filled in 10.321 seconds. > Bytes counted in 0.596 seconds. > > What is going on here? The i7 should be way faster than an > XP-generation machine. What cpu does the XP machine have? > > Anyway, the speed is pretty good. I might try using ocaml. On i7-4790: Array filled in 1.940 seconds. Bytes counted in 0.133 seconds. 256MiB: Array filled in 5.247 seconds. Bytes counted in 0.363 seconds. Haskell version is somewhat faster: length: 268435456 init time: 5.106665 count time: 0.253333 import System.CPUTime import qualified Data.Vector.Unboxed as U import qualified Data.Vector.Unboxed.Mutable as UM import System.Random.Mersenne import Data.Word import Text.Printf main = do g <- newMTGen Nothing rs <- randoms g let a = U.fromList (take (2^28) rs) :: U.Vector Word8 diff b e = (fromIntegral (e - b)) / (10^12) begin <- getCPUTime putStrLn $ "length: " ++ show (U.length a) -- to force calculation end <- getCPUTime putStrLn $ "init time: " ++ show (diff begin end) begin' <- getCPUTime table <- UM.new 256 :: IO (UM.IOVector Int) U.mapM_ (\x -> do let x' = fromIntegral x v <- UM.unsafeRead table x' UM.unsafeWrite table x' (v+1)) a end' <- getCPUTime putStrLn $ "count time: " ++ show (diff begin' end') out <- U.unsafeFreeze table let out' = zip [0..] $ U.toList out wlist = foldl (\x (a,b)-> if a `mod` 5 > 0 then printf "%s %3d : %-7d" x (a::Int) (b::Int) else printf "%s\n%3d : %-7d" x (a::Int) (b::Int)) "" out' max = foldl (\(a,b) (c,d)-> if b > d then (a,b) else (c,d)) (head out') (tail out') putStrLn $ wlist++"\nmaximum: " ++ show max