Commit b7d3c264 authored by Hans-Peter Deifel's avatar Hans-Peter Deifel 🐢

Add micro-benchmarks for lexer

The lexer is one of the bottlenecks for parsing. With these
fine-grained benchmarks, we can make more educated guesses about what
to optimize.
parent e6ca3a62
......@@ -4,9 +4,11 @@ import Criterion.Main
import qualified MA.Coalgebra.BenchParser
import qualified MA.Functors.BenchMonoidValued
import qualified MA.Parser.BenchLexer
main :: IO ()
main = defaultMain
[ MA.Coalgebra.BenchParser.benchmarks
, MA.Functors.BenchMonoidValued.benchmarks
, MA.Parser.BenchLexer.benchmarks
]
......@@ -19,7 +19,7 @@ import MA.Coalgebra.RefinementTypes
import MA.Functors.MonoidValued
benchmarks :: Benchmark
benchmarks = bgroup "MA.Functors.BenchMonoid"
benchmarks = bgroup "MA.Functors.Monoid"
[ benchIntValued
]
......
{-# LANGUAGE FlexibleContexts #-}
module MA.Parser.BenchLexer (benchmarks) where
import Criterion
import Text.Megaparsec
import Data.Text (Text)
import Control.DeepSeq (NFData)
import MA.Parser.Types
import qualified MA.Parser.Lexer as L
benchmarks :: Benchmark
benchmarks = bgroup "MA.Parser.Lexer"
[ benchColon
, benchDecimal
, benchFloat
, benchName
, benchSpace
]
benchColon :: Benchmark
benchColon = bgroup "colon"
[ benchp "single" L.colon ":"
, benchp "ten" L.colon "::::::::::"
, benchp "failing" L.colon "."
]
benchDecimal :: Benchmark
benchDecimal = bgroup "decimal"
[ benchp @Int "single" L.decimal "1"
, benchp @Int "many" L.decimal "111111111"
, benchp @Int "signed" (L.signed L.decimal) "-111111111"
]
benchFloat :: Benchmark
benchFloat = bgroup "float"
[ benchp @Double "integer" L.float "1"
, benchp @Double "real" L.float "2.87182364"
, benchp @Double "signed" (L.signed L.float) "2.87182364"
]
benchName :: Benchmark
benchName = bgroup "name"
[ benchp "one letter" L.name "a"
, benchp "100 letters" L.name "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
, benchp "1 letter and 99 problems" L.name "a999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"
, benchp "love letters" L.name "love"
]
benchSpace :: Benchmark
benchSpace = bgroup "space"
[ benchp "one space" L.spaceConsumer " "
, benchp "some space" L.spaceConsumer " "
, benchp "comment" L.spaceConsumer "# A comment"
, benchp "space, comment, space" L.spaceConsumer " # A comment\n "
]
benchp :: NFData a => String -> Parser a -> Text -> Benchmark
benchp name p input = bench name (nf (parse p "") input)
......@@ -168,6 +168,7 @@ benchmark bench
main-is: BenchMain.hs
other-modules: MA.Coalgebra.BenchParser
, MA.Functors.BenchMonoidValued
, MA.Parser.BenchLexer
default-extensions: GADTs
, StandaloneDeriving
, DeriveFunctor
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment