File: Multilang.hs

package info (click to toggle)
haskell-text 1.2.0.6-1~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 900 kB
  • sloc: haskell: 9,299; ansic: 238; python: 87; ruby: 84; sh: 49; makefile: 29
file content (32 lines) | stat: -rw-r--r-- 789 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
{-# LANGUAGE BangPatterns, OverloadedStrings, RankNTypes #-}

module Main (
  main
  ) where

import Control.Monad (forM_)
import qualified Data.ByteString as B
import qualified Data.Text as Text
import Data.Text.Encoding (decodeUtf8)
import Data.Text (Text)
import System.IO (hFlush, stdout)
import Timer (timer)

type BM = Text -> ()

bm :: forall a. (Text -> a) -> BM
bm f t = f t `seq` ()

benchmarks :: [(String, Text.Text -> ())]
benchmarks = [
    ("find_first", bm $ Text.isInfixOf "en:Benin")
  , ("find_index", bm $ Text.findIndex (=='c'))
  ]

main :: IO ()
main = do
  !contents <- decodeUtf8 `fmap` B.readFile "../tests/text-test-data/yiwiki.xml"
  forM_ benchmarks $ \(name, bmark) -> do
    putStr $ name ++ " "
    hFlush stdout
    putStrLn =<< (timer 100 contents bmark)