Hi, I have tried to implement knucleotide benchmark program this time:Implementation is shorter (uses hashtable from hashtables package),but two time slower then current Haskell entry ( which is too low levelfor my taste :)).What is interesting is that if I try to place Int64 as a key tohash table, performance is even slower.Strange that dropping and taking from bytestring would befaster than packing string in 64 bit int and directly indexing.If someone can see something that can bring performance on parwith current haskell entry , I would post it , otherwise no point,except that program is shorter and not low level.{-# Language BangPatterns #-}---- The Computer Language Benchmarks Game---- Contributed by Branimir Maksimovic--import Data.Charimport Data.Listimport Data.IORefimport qualified Data.HashTable.IO as Himport qualified Data.ByteString.Char8 as Simport Control.Concurrentimport Text.Printfmain = dos <- S.getContentslet content = (S.map toUpper . S.concat . tail .dropWhile (\l->not $ S.isPrefixOf (S.pack ">THREE") l) .S.lines) smapM_ (execute content) actionsdata Actions = I Int | S Stringactions = [I 1,I 2,S "GGT",S "GGTA",S "GGTATT",S "GGTATTTTAATT",S "GGTATTTTAATTTATAGT"]execute content (I i) = writeFrequencies content iexecute content (S s) = writeCount content swriteFrequencies input size = doht <- tcalculate input sizelst <- H.foldM (\lst (k,v)->dov' <- readIORef vreturn $ insertBy (\(_,x) (_,y)->y `compare` x) (k,v') lst) [] htlet sum = fromIntegral ((S.length input) + 1 - size)mapM_ (\(k,v)-> doprintf "%s %.3f\n"(S.unpack k) ((100 * (fromIntegral v)/sum)::Double)) lstputChar '\n'writeCount input string = dolet size = length stringht <- tcalculate input sizeres <- H.lookup ht (S.pack string)case res ofNothing -> putStrLn $ string ++ " not found..."Just v -> dor <- readIORef vprintf "%d\t%s\n" r (string::String)tcalculate input size = doletl = [0..7]actions = map (\i -> (calculate input i size (length l))) lvars <- mapM (\action -> dovar <- newEmptyMVarforkIO $ doanswer <- actionputMVar var answerreturn var) actionsresult <- newTableresults <- mapM takeMVar varsmapM_ (\ht -> H.foldM (\lst (k,v) -> dores <- H.lookup lst kcase res ofNothing -> dor1 <- readIORef vr2 <- newIORef r1H.insert lst k r2Just v1 -> dor1 <- readIORef v1r2 <- readIORef vwriteIORef v1 (r1+r2)return lst) result ht) resultsreturn resultcalculate input beg size incr = doht <- newTableletcalculate' :: S.ByteString -> Int -> IO HashTablecalculate' str i| i >= ((S.length input)+1 - size) = return ht| otherwise = dores <- H.lookup ht kcase res ofNothing -> do!r <- newIORef 1H.insert ht k rJust v -> do!r <- readIORef vwriteIORef v (r+1)calculate' (S.drop incr str) (i+incr)where k = S.take size strcalculate' (S.drop beg input) begtype HashTable = H.BasicHashTable S.ByteString (IORef Int)newTable :: IO HashTablenewTable = H.new
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe