File: NormalizationBench.hs

package info (click to toggle)
haskell-unicode-data 0.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,004 kB
  • sloc: haskell: 26,075; makefile: 3
file content (54 lines) | stat: -rw-r--r-- 1,736 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
module Unicode.Char.NormalizationBench
    ( benchmarks
    ) where

import Test.Tasty.Bench ( bgroup, Benchmark )

import Unicode.Char.Bench (
    Bench (..),
    CharRange,
    bgroupWithCharRange,
    bgroupWithChars,
    bgroupWithValidCharRange',
 )
import qualified Unicode.Char.General as G
import qualified Unicode.Char.Normalization as N

{-# NOINLINE benchmarks #-}
benchmarks :: CharRange -> Benchmark
benchmarks r = bgroupWithCharRange "Unicode.Char.Normalization" r $ \chars ->
    [ bgroupWithChars "isCombining" chars
      [ Bench "unicode-data" N.isCombining
      ]
    , bgroupWithChars "combiningClass" chars
      [ Bench "unicode-data" N.combiningClass
      ]
    , bgroupWithChars "isCombiningStarter" chars
      [ Bench "unicode-data" N.isCombiningStarter
      ]
    -- [TODO] compose, composeStarters
    , bgroup "isDecomposable"
      [ bgroupWithChars "Canonical" chars
        [ Bench "unicode-data" (N.isDecomposable N.Canonical)
        ]
      , bgroupWithChars "Kompat" chars
        [ Bench "unicode-data" (N.isDecomposable N.Kompat)
        ]
      ]
    , bgroup "decompose"
      [ bgroupWithValidCharRange' "Canonical" r (isValid N.Canonical)
        [ Bench "unicode-data" (N.decompose N.Canonical)
        ]
      , bgroupWithValidCharRange' "Kompat" r (isValid N.Kompat)
        [ Bench "unicode-data" (N.decompose N.Kompat)
        ]
      ]
    , bgroupWithChars "decomposeHangul" chars
      [ Bench "unicode-data" N.decomposeHangul
      ]
    ]

-- Filter out: Surrogates, Private Use Areas and unsassigned code points
--             and non-decomposable characters
isValid :: N.DecomposeMode -> Char -> Bool
isValid mode c = G.generalCategory c < G.Surrogate && N.isDecomposable mode c