Skip to content

Add a simple benchmark module #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@
output
generated-docs
bower_components

node_modules
package.json
package-lock.json
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Bugfixes:

Other improvements:
- Added `purs-tidy` formatter (#76 by @thomashoneyman)

- Add a benchmark module (#79 by @chtenb)
- Run slowest tests last and print status updates (#72)

## [v6.0.1](https://github.com/purescript-contrib/purescript-string-parsers/releases/tag/v6.0.1) - 2021-05-11
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,11 @@ You can contribute to `string-parsers` in several ways:
2. If you would like to contribute code, tests, or documentation, please [read the contributor guide](./CONTRIBUTING.md). It's a short, helpful introduction to contributing to this library, including development instructions.

3. If you have written a library, tutorial, guide, or other resource based on this package, please share it on the [PureScript Discourse](https://discourse.purescript.org)! Writing libraries and learning resources are a great way to help this library succeed.

## Benchmark

To execute the benchmarks run the following command

```
spago run --main Bench.Main
```
75 changes: 75 additions & 0 deletions bench/Main.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
-- | # Benchmarking
-- |
-- | spago run --main Bench.Main
-- |
-- | This benchmark suite is intended to guide changes to this package so that
-- | we can compare the benchmarks of different commits.


module Bench.Main where

import Prelude

import Data.Array (fold, replicate)
import Data.List (manyRec)
import Data.List.Types (List)
import Effect (Effect)
import Effect.Console (log)
import Performance.Minibench (benchWith)
import Text.Parsing.StringParser (Parser, runParser)
import Text.Parsing.StringParser.CodePoints as StringParser.CodePoints
import Text.Parsing.StringParser.CodeUnits as StringParser.CodeUnits

string23 :: String
string23 = "23"

string23_2 :: String
string23_2 = fold $ replicate 2 string23

string23_10000 :: String
string23_10000 = fold $ replicate 10000 string23

parse23DigitPoints :: Parser (List Char)
parse23DigitPoints = manyRec StringParser.CodePoints.anyDigit

parse23DigitUnits :: Parser (List Char)
parse23DigitUnits = manyRec StringParser.CodeUnits.anyDigit

parse23StringPoints :: Parser (List String)
parse23StringPoints = manyRec $ StringParser.CodePoints.string "23"

parse23StringUnits :: Parser (List String)
parse23StringUnits = manyRec $ StringParser.CodeUnits.string "23"

parse23RegexPoints :: Parser (List String)
parse23RegexPoints = manyRec $ StringParser.CodePoints.regex """\d\d"""

parse23RegexUnits :: Parser (List String)
parse23RegexUnits = manyRec $ StringParser.CodeUnits.string """\d\d"""

main :: Effect Unit
main = do
-- log $ show $ runParser string23_2 parse23
-- log $ show $ Regex.match pattern23 string23_2
-- log $ show $ runParser stringSkidoo_2 parseSkidoo
-- log $ show $ Regex.match patternSkidoo stringSkidoo_2
log "StringParser.runParser parse23DigitPoints"
benchWith 20
$ \_ -> runParser parse23DigitPoints string23_10000
log "StringParser.runParser parse23DigitUnits"
benchWith 200
$ \_ -> runParser parse23DigitUnits string23_10000

log "StringParser.runParser parse23StringPoints"
benchWith 20
$ \_ -> runParser parse23StringPoints string23_10000
log "StringParser.runParser parse23StringUnits"
benchWith 200
$ \_ -> runParser parse23StringUnits string23_10000

log "StringParser.runParser parse23RegexPoints"
benchWith 20
$ \_ -> runParser parse23RegexPoints string23_10000
log "StringParser.runParser parse23RegexUnits"
benchWith 200
$ \_ -> runParser parse23RegexUnits string23_10000
3 changes: 2 additions & 1 deletion spago.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
, "foldable-traversable"
, "lists"
, "maybe"
, "minibench"
, "nonempty"
, "prelude"
, "psci-support"
Expand All @@ -19,5 +20,5 @@
, "unfoldable"
]
, packages = ./packages.dhall
, sources = [ "src/**/*.purs", "test/**/*.purs" ]
, sources = [ "src/**/*.purs", "test/**/*.purs", "bench/**/*.purs" ]
}