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 qualified Data.Attoparsec.ByteString as AP.ByteString
13 import qualified Data.Attoparsec.Text as AP.Text
14 import qualified Data.ByteString as BS
15 import qualified Data.ByteString.Lazy as BSL
16 import qualified Data.List as List
17 import qualified Data.Text.IO as Text
18 import qualified System.IO as IO
20 import qualified Parsers.Brainfuck.Attoparsec as AP.Brainfuck
21 import qualified Parsers.Brainfuck.Handrolled as HR.Brainfuck
22 import qualified Parsers.Brainfuck.SymanticParser as SP.Brainfuck
23 import Paths_symantic_parser
25 inputPath inputName = getDataFileName ("parsers/Parsers/Brainfuck/inputs/"<>inputName<>".bf")
26 benchBrainfuck inputName =
28 [ env (Text.readFile =<< inputPath inputName) $ \inp ->
30 [ bench "SymanticParser" $
31 nf SP.Brainfuck.parserText inp
32 , bench "Attoparsec" $
33 nf (AP.Text.parse AP.Brainfuck.parser) inp
34 , bench "Handrolled" $
35 nf HR.Brainfuck.parser inp
39 [ env (IO.readFile =<< inputPath inputName) $ \inp ->
41 [ bench "SymanticParser" $
42 nf SP.Brainfuck.parserString inp
46 [ env (BS.readFile =<< inputPath inputName) $ \inp ->
48 [ bench "SymanticParser" $
49 nf SP.Brainfuck.parserByteString inp
50 , bench "Attoparsec" $
51 nf (AP.ByteString.parse AP.Brainfuck.parser) inp
52 , bench "Handrolled" $
53 nf HR.Brainfuck.parser inp
56 , bgroup "ByteStringLazy"
57 [ env (BSL.readFile =<< inputPath inputName) $ \inp ->
59 [ bench "SymanticParser" $
60 nf SP.Brainfuck.parserByteStringLazy inp
65 benchmark :: Benchmark
66 benchmark = bgroup "Brainfuck" $ List.concat
67 [ benchBrainfuck "compiler"
68 , benchBrainfuck "hanoi"