File: Main.hs

package info (click to toggle)
haskell-xlsx 1.1.2.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 860 kB
  • sloc: haskell: 12,602; makefile: 6
file content (48 lines) | stat: -rw-r--r-- 1,657 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
{-# LANGUAGE OverloadedStrings #-}
module Main (main) where

import Codec.Xlsx
import Codec.Xlsx.Parser.Stream
import Codec.Xlsx.Writer.Stream
import Control.DeepSeq
import Control.Lens
import Control.Monad (void)
import Criterion.Main
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as LB
import qualified Data.Conduit as C
import qualified Data.Conduit.Combinators as C
import Data.Maybe

main :: IO ()
main = do
  let filename = "data/testInput.xlsx"
        -- "data/6000.rows.x.26.cols.xlsx"
  bs <- BS.readFile filename
  let bs' = LB.fromStrict bs
      parsed :: Xlsx
      parsed = toXlsxFast bs'
  idx <- fmap (fromMaybe (error "ix not found")) $ runXlsxM filename $ makeIndexFromName "Sample list"
  items <- runXlsxM filename $ collectItems idx
  deepseq (parsed, bs', idx, items) (pure ())
  defaultMain
    [ bgroup
        "readFile"
        [ bench "with xlsx" $ nf toXlsx bs'
        , bench "with xlsx fast" $ nf toXlsxFast bs'
        , bench "with stream (counting)" $ nfIO $ runXlsxM filename $ countRowsInSheet idx
        , bench "with stream (reading)" $ nfIO $ runXlsxM filename $ readSheet idx (pure . rwhnf)
        ]
    , bgroup
        "writeFile"
        [ bench "with xlsx" $ nf (fromXlsx 0) parsed
        , bench "with stream (no sst)" $
          nfIO $ C.runConduit $
            void (writeXlsxWithSharedStrings defaultSettings mempty $ C.yieldMany $ view si_row <$> items)
            C..| C.fold
        , bench "with stream (sst)" $
          nfIO $ C.runConduit $
            void (writeXlsx defaultSettings $ C.yieldMany $ view si_row <$> items)
            C..| C.fold
        ]
    ]