[Haskell-cafe] How to speed things up

Greg Buchholz haskell at sleepingsquirrel.org
Thu Apr 28 13:23:30 EDT 2005


Greg Buchholz wrote:
>   You'd probably get a faster program with Unboxed arrays and
>   unsafeAccumArray.
>  

    Yeah, its about 20x faster unboxed and unsafe...

import Data.Array.Base

main = print $ quick_func $ take 1000000 $ cycle [1,2,3,1,2,9,1,9]

quick_func :: [Int] -> [(Int,Int)]
quick_func is = assocs f
    where
       f :: UArray Int Int
       f =  unsafeAccumArray (+) 0 (1,12) [(i, 1::Int) | i<-is]
           




More information about the Haskell-Cafe mailing list