File: Sorting.hs

package info (click to toggle)
haskell-mono-traversable 1.0.20.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 280 kB
  • sloc: haskell: 3,596; makefile: 7
file content (43 lines) | stat: -rw-r--r-- 1,251 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
{-# LANGUAGE CPP #-}
module Sorting (sortingBenchmarks) where

#if MIN_VERSION_gauge(0,2,0)
import Gauge
#else
import Gauge.Main
#endif

import Data.Sequences
import Data.MonoTraversable
import qualified Data.List
import qualified System.Random.MWC as MWC
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as U
import System.IO.Unsafe (unsafePerformIO)

sortingBenchmarks :: Benchmark
sortingBenchmarks
  = bgroup "Sorting"
  $ unsafePerformIO
  $ mapM mkGroup [10, 100, 1000, 10000]

asVector :: V.Vector a -> V.Vector a
asVector = id

asUVector :: U.Vector a -> U.Vector a
asUVector = id

mkGroup :: Int -> IO Benchmark
mkGroup size = do
    gen <- MWC.create
    inputV <- MWC.uniformVector gen size
    let inputL = otoList (inputV :: V.Vector Int)
        inputVU = fromList inputL :: U.Vector Int
    return $ bgroup (show size)
        [ bench "Data.List.sort" $ nf Data.List.sort inputL
        , bench "list sort" $ nf sort inputL
        , bench "list sort, via vector" $ nf (otoList . sort . asVector . fromList) inputL
        , bench "list sort, via uvector" $ nf (otoList . sort . asUVector . fromList) inputL
        , bench "vector sort" $ nf sort inputV
        , bench "uvector sort" $ nf sort inputVU
        ]