1 {-# LANGUAGE TemplateHaskell #-}
2 {-# LANGUAGE TypeApplications #-}
3 {-# LANGUAGE TypeFamilies #-}
4 {-# OPTIONS_GHC -Wno-missing-signatures #-}
7 --import qualified Data.Text.Lazy as TL
8 import Control.Monad ((=<<))
9 import Criterion.Main (Benchmark, bench, bgroup, env, nf)
10 import Data.Function (($))
11 import Data.Semigroup (Semigroup(..))
12 import Data.String (String)
13 import Data.Text (Text)
14 import qualified Data.Attoparsec.ByteString as AP.ByteString
15 import qualified Data.Attoparsec.Text as AP.Text
16 import qualified Data.ByteString as BS
17 import qualified Data.ByteString.Lazy as BSL
18 import qualified Data.List as List
19 import qualified Data.Text.IO as Text
20 import qualified System.IO as IO
22 import qualified Symantic.Parser as SP
23 import qualified Parsers.Brainfuck.Attoparsec as AP.Brainfuck
24 import qualified Parsers.Brainfuck.Handrolled as HR.Brainfuck
25 import qualified Parsers.Brainfuck.SymanticParser as SP.Brainfuck
26 import Paths_symantic_parser
28 inputPath inputName = getDataFileName ("parsers/Parsers/Brainfuck/inputs/"<>inputName<>".bf")
29 benchBrainfuck inputName =
31 [ env (Text.readFile =<< inputPath inputName) $ \inp ->
33 [ bench "SymanticParser" $
34 nf SP.Brainfuck.parserText inp
35 , bench "Attoparsec" $
36 nf (AP.Text.parse AP.Brainfuck.parser) inp
37 , bench "Handrolled" $
38 nf HR.Brainfuck.parser inp
42 [ env (IO.readFile =<< inputPath inputName) $ \inp ->
44 [ bench "SymanticParser" $
45 nf SP.Brainfuck.parserString inp
49 [ env (BS.readFile =<< inputPath inputName) $ \inp ->
51 [ bench "SymanticParser" $
52 nf SP.Brainfuck.parserByteString inp
53 , bench "Attoparsec" $
54 nf (AP.ByteString.parse AP.Brainfuck.parser) inp
55 , bench "Handrolled" $
56 nf HR.Brainfuck.parser inp
59 , bgroup "ByteStringLazy"
60 [ env (BSL.readFile =<< inputPath inputName) $ \inp ->
62 [ bench "SymanticParser" $
63 nf SP.Brainfuck.parserByteStringLazy inp
68 benchmark :: Benchmark
69 benchmark = bgroup "Brainfuck" $ List.concat
70 [ benchBrainfuck "helloworld"
71 , benchBrainfuck "compiler"
72 , benchBrainfuck "hanoi"