File: Main.hs

package info (click to toggle)
haskell-text-metrics 0.3.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 112 kB
  • sloc: haskell: 409; makefile: 7
file content (34 lines) | stat: -rw-r--r-- 1,053 bytes parent folder | download | duplicates (2)
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
module Main (main) where

import Control.DeepSeq
import Criterion.Main
import Data.Text (Text)
import qualified Data.Text as T
import Data.Text.Metrics

main :: IO ()
main =
  defaultMain
    [ btmetric "levenshtein" levenshtein,
      btmetric "levenshteinNorm" levenshteinNorm,
      btmetric "damerauLevenshtein" damerauLevenshtein,
      btmetric "damerauLevenshteinNorm" damerauLevenshteinNorm,
      btmetric "overlap" overlap,
      btmetric "jaccard" jaccard,
      btmetric "hamming" hamming,
      btmetric "jaro" jaro,
      btmetric "jaroWinkler" jaroWinkler
    ]

-- | Produce benchmark group to test.
btmetric :: NFData a => String -> (Text -> Text -> a) -> Benchmark
btmetric name f = bgroup name (bs <$> stdSeries)
  where
    bs n = env (return (testData n, testData n)) (bench (show n) . nf (uncurry f))

-- | The series of lengths to try with every function as part of 'btmetric'.
stdSeries :: [Int]
stdSeries = [5, 10, 20, 40, 80, 160]

testData :: Int -> Text
testData n = T.pack . take n . drop (n `mod` 4) . cycle $ ['a' .. 'z']