text / benchmarks / haskell / Multilang.hs

The default branch has multiple heads

{-# LANGUAGE BangPatterns, OverloadedStrings, RankNTypes #-}

module 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)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.