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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
{-# LANGUAGE OverloadedStrings #-}
-- Module : Main
-- Copyright : (c) 2014-2020 Brendan Hay <brendan.g.hay@gmail.com>
-- License : This Source Code Form is subject to the terms of
-- the Mozilla Public License, v. 2.0.
-- A copy of the MPL can be found in the LICENSE file or
-- you can obtain it at http://mozilla.org/MPL/2.0/.
-- Maintainer : Brendan Hay <brendan.g.hay@gmail.com>
-- Stability : experimental
-- Portability : non-portable (GHC extensions)
module Main (main) where
import Criterion
import Criterion.Main
import Data.List (intersperse)
import Data.Monoid
import Data.Text (Text)
import qualified Data.Text as Text
import Data.Text.Manipulate
main :: IO ()
main =
defaultMain
[ bgroup
"Data.Text"
[ bench "takeWord" $
whnf (Text.takeWhile (not . isWordBoundary)) phrase,
bench "toCamel" $
whnf (lowerHead . mconcat . group Text.toTitle) phrase,
bench "toPascal" $
whnf (upperHead . mconcat . group Text.toTitle) phrase,
bench "toSnake" $
whnf (mconcat . intersperse "_" . group Text.toLower) phrase,
bench "toSpinal" $
whnf (mconcat . intersperse "-" . group Text.toLower) phrase,
bench "toTrain" $
whnf (mconcat . intersperse "-" . group Text.toTitle) phrase
],
bgroup
"Data.Text.Case"
[ bench "takeWord" $ whnf takeWord phrase,
bench "toCamel" $ whnf toCamel phrase,
bench "toPacal" $ whnf toPascal phrase,
bench "toSnake" $ whnf toSnake phrase,
bench "toSpinal" $ whnf toSpinal phrase,
bench "toTrain" $ whnf toTrain phrase
]
]
phrase :: Text
phrase = "Supercalifragilistic, world! This-is A multipleDelimiter_String"
group :: (Text -> Text) -> Text -> [Text]
group f =
map (f . Text.dropWhile isBoundary)
. Text.groupBy (const (not . isWordBoundary))
|