]> Git — Sourcephile - haskell/symantic-parser.git/blob - benchmarks/Brainfuck.hs
remove useless benchmarks
[haskell/symantic-parser.git] / benchmarks / Brainfuck.hs
1 {-# LANGUAGE TemplateHaskell #-}
2 {-# LANGUAGE TypeApplications #-}
3 {-# LANGUAGE TypeFamilies #-}
4 {-# OPTIONS_GHC -Wno-missing-signatures #-}
5 module Brainfuck where
6
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
21
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
27
28 inputPath inputName = getDataFileName ("parsers/Parsers/Brainfuck/inputs/"<>inputName<>".bf")
29 benchBrainfuck inputName =
30 [ bgroup "Text"
31 [ env (Text.readFile =<< inputPath inputName) $ \inp ->
32 bgroup inputName
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
39 ]
40 ]
41 , bgroup "String"
42 [ env (IO.readFile =<< inputPath inputName) $ \inp ->
43 bgroup inputName
44 [ bench "SymanticParser" $
45 nf SP.Brainfuck.parserString inp
46 ]
47 ]
48 , bgroup "ByteString"
49 [ env (BS.readFile =<< inputPath inputName) $ \inp ->
50 bgroup inputName
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
57 ]
58 ]
59 , bgroup "ByteStringLazy"
60 [ env (BSL.readFile =<< inputPath inputName) $ \inp ->
61 bgroup inputName
62 [ bench "SymanticParser" $
63 nf SP.Brainfuck.parserByteStringLazy inp
64 ]
65 ]
66 ]
67
68 benchmark :: Benchmark
69 benchmark = bgroup "Brainfuck" $ List.concat
70 [ benchBrainfuck "helloworld"
71 , benchBrainfuck "compiler"
72 , benchBrainfuck "hanoi"
73 ]