File: Main.hs

package info (click to toggle)
haskell-text-metrics 0.3.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 88 kB
  • sloc: haskell: 411; makefile: 3
file content (39 lines) | stat: -rw-r--r-- 1,123 bytes parent folder | download
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
module Main (main) where

import Control.DeepSeq
import Control.Monad
import Data.Text (Text)
import Data.Text qualified as T
import Data.Text.Metrics
import Weigh

main :: IO ()
main = mainWith $ do
  setColumns [Case, Allocated, GCs, Max]
  bmetric "levenshtein" levenshtein
  bmetric "levenshteinNorm" levenshteinNorm
  bmetric "damerauLevenshtein" damerauLevenshtein
  bmetric "damerauLevenshteinNorm" damerauLevenshteinNorm
  bmetric "overlap" overlap
  bmetric "jaccard" jaccard
  bmetric "hamming" hamming
  bmetric "jaro" jaro
  bmetric "jaroWinkler" jaroWinkler

-- | Perform a series to measurements with the same metric function.
bmetric ::
  (NFData a) =>
  -- | Name of the benchmark group
  String ->
  -- | The function to benchmark
  (Text -> Text -> a) ->
  Weigh ()
bmetric name f = forM_ stdSeries $ \n ->
  func (name ++ "/" ++ show n) (uncurry f) (testData n, testData n)

-- | 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']