on 1.1 help sign in
text/benchmarks/haskell/Multilang.hs
32 lines 789 B history raw
1{-# LANGUAGE BangPatterns, OverloadedStrings, RankNTypes #-}
3module Main (
4 main
5 ) where
7import Control.Monad (forM_)
8import qualified Data.ByteString as B
9import qualified Data.Text as Text
10import Data.Text.Encoding (decodeUtf8)
11import Data.Text (Text)
12import System.IO (hFlush, stdout)
13import Timer (timer)
15type BM = Text -> ()
17bm :: forall a. (Text -> a) -> BM
18bm f t = f t `seq` ()
20benchmarks :: [(String, Text.Text -> ())]
21benchmarks = [
22 ("find_first", bm $ Text.isInfixOf "en:Benin")
23 , ("find_index", bm $ Text.findIndex (=='c'))
24 ]
26main :: IO ()
27main = do
28 !contents <- decodeUtf8 `fmap` B.readFile "../tests/text-test-data/yiwiki.xml"
29 forM_ benchmarks $ \(name, bmark) -> do
30 putStr $ name ++ " "
31 hFlush stdout
32 putStrLn =<< (timer 100 contents bmark)