File: InverseBench.hs

package info (click to toggle)
haskell-arithmoi 0.13.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 964 kB
  • sloc: haskell: 10,379; makefile: 3
file content (60 lines) | stat: -rw-r--r-- 2,018 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
{-# LANGUAGE FlexibleContexts      #-}
{-# LANGUAGE TypeApplications      #-}

{-# OPTIONS_GHC -fno-warn-type-defaults #-}

module Math.NumberTheory.InverseBench
  ( benchSuite
  ) where

import Test.Tasty.Bench
import Data.Bits (Bits)
import Data.Euclidean
import Numeric.Natural

import Math.NumberTheory.ArithmeticFunctions.Inverse
import Math.NumberTheory.Primes

fact :: (Enum a, Num a) => a
fact = product [1..13]

tens :: Num a => a
tens = 10 ^ 18

countInverseTotient :: (Ord a, Integral a, Euclidean a, UniqueFactorisation a) => a -> Word
countInverseTotient = inverseTotient (const 1)

countInverseSigma :: (Integral a, Euclidean a, UniqueFactorisation a, Enum (Prime a), Bits a) => a -> Word
countInverseSigma = inverseSigma (const 1)

benchSuite :: Benchmark
benchSuite = bgroup "Inverse"
  [ bgroup "Totient"
    [ bgroup "factorial"
      [ bench "Int"     $ nf (countInverseTotient @Int)     fact
      , bench "Word"    $ nf (countInverseTotient @Word)    fact
      , bench "Integer" $ nf (countInverseTotient @Integer) fact
      , bench "Natural" $ nf (countInverseTotient @Natural) fact
      ]
    , bgroup "power of 10"
      [ bench "Int"     $ nf (countInverseTotient @Int)     tens
      , bench "Word"    $ nf (countInverseTotient @Word)    tens
      , bench "Integer" $ nf (countInverseTotient @Integer) tens
      , bench "Natural" $ nf (countInverseTotient @Natural) tens
      ]
    ]
  , bgroup "Sigma1"
    [ bgroup "factorial"
      [ bench "Int"     $ nf (countInverseSigma @Int)     fact
      , bench "Word"    $ nf (countInverseSigma @Word)    fact
      , bench "Integer" $ nf (countInverseSigma @Integer) fact
      , bench "Natural" $ nf (countInverseSigma @Natural) fact
      ]
    , bgroup "power of 10"
      [ bench "Int"     $ nf (countInverseSigma @Int)     tens
      , bench "Word"    $ nf (countInverseSigma @Word)    tens
      , bench "Integer" $ nf (countInverseSigma @Integer) tens
      , bench "Natural" $ nf (countInverseSigma @Natural) tens
      ]
    ]
  ]