Skip to content

Commit dc25d26

Browse files
authored
Add a simple benchmark module (#79)
* Add a simple benchmark module * update readme * update changelog
1 parent 319b8f5 commit dc25d26

File tree

5 files changed

+90
-2
lines changed

5 files changed

+90
-2
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@
77
output
88
generated-docs
99
bower_components
10+
11+
node_modules
12+
package.json
13+
package-lock.json

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Bugfixes:
1212

1313
Other improvements:
1414
- Added `purs-tidy` formatter (#76 by @thomashoneyman)
15-
15+
- Add a benchmark module (#79 by @chtenb)
1616
- Run slowest tests last and print status updates (#72)
1717

1818
## [v6.0.1](https://github.com/purescript-contrib/purescript-string-parsers/releases/tag/v6.0.1) - 2021-05-11

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,11 @@ You can contribute to `string-parsers` in several ways:
4545
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.
4646

4747
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.
48+
49+
## Benchmark
50+
51+
To execute the benchmarks run the following command
52+
53+
```
54+
spago run --main Bench.Main
55+
```

bench/Main.purs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
-- | # Benchmarking
2+
-- |
3+
-- | spago run --main Bench.Main
4+
-- |
5+
-- | This benchmark suite is intended to guide changes to this package so that
6+
-- | we can compare the benchmarks of different commits.
7+
8+
9+
module Bench.Main where
10+
11+
import Prelude
12+
13+
import Data.Array (fold, replicate)
14+
import Data.List (manyRec)
15+
import Data.List.Types (List)
16+
import Effect (Effect)
17+
import Effect.Console (log)
18+
import Performance.Minibench (benchWith)
19+
import Text.Parsing.StringParser (Parser, runParser)
20+
import Text.Parsing.StringParser.CodePoints as StringParser.CodePoints
21+
import Text.Parsing.StringParser.CodeUnits as StringParser.CodeUnits
22+
23+
string23 :: String
24+
string23 = "23"
25+
26+
string23_2 :: String
27+
string23_2 = fold $ replicate 2 string23
28+
29+
string23_10000 :: String
30+
string23_10000 = fold $ replicate 10000 string23
31+
32+
parse23DigitPoints :: Parser (List Char)
33+
parse23DigitPoints = manyRec StringParser.CodePoints.anyDigit
34+
35+
parse23DigitUnits :: Parser (List Char)
36+
parse23DigitUnits = manyRec StringParser.CodeUnits.anyDigit
37+
38+
parse23StringPoints :: Parser (List String)
39+
parse23StringPoints = manyRec $ StringParser.CodePoints.string "23"
40+
41+
parse23StringUnits :: Parser (List String)
42+
parse23StringUnits = manyRec $ StringParser.CodeUnits.string "23"
43+
44+
parse23RegexPoints :: Parser (List String)
45+
parse23RegexPoints = manyRec $ StringParser.CodePoints.regex """\d\d"""
46+
47+
parse23RegexUnits :: Parser (List String)
48+
parse23RegexUnits = manyRec $ StringParser.CodeUnits.string """\d\d"""
49+
50+
main :: Effect Unit
51+
main = do
52+
-- log $ show $ runParser string23_2 parse23
53+
-- log $ show $ Regex.match pattern23 string23_2
54+
-- log $ show $ runParser stringSkidoo_2 parseSkidoo
55+
-- log $ show $ Regex.match patternSkidoo stringSkidoo_2
56+
log "StringParser.runParser parse23DigitPoints"
57+
benchWith 20
58+
$ \_ -> runParser parse23DigitPoints string23_10000
59+
log "StringParser.runParser parse23DigitUnits"
60+
benchWith 200
61+
$ \_ -> runParser parse23DigitUnits string23_10000
62+
63+
log "StringParser.runParser parse23StringPoints"
64+
benchWith 20
65+
$ \_ -> runParser parse23StringPoints string23_10000
66+
log "StringParser.runParser parse23StringUnits"
67+
benchWith 200
68+
$ \_ -> runParser parse23StringUnits string23_10000
69+
70+
log "StringParser.runParser parse23RegexPoints"
71+
benchWith 20
72+
$ \_ -> runParser parse23RegexPoints string23_10000
73+
log "StringParser.runParser parse23RegexUnits"
74+
benchWith 200
75+
$ \_ -> runParser parse23RegexUnits string23_10000

spago.dhall

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
, "foldable-traversable"
1212
, "lists"
1313
, "maybe"
14+
, "minibench"
1415
, "nonempty"
1516
, "prelude"
1617
, "psci-support"
@@ -19,5 +20,5 @@
1920
, "unfoldable"
2021
]
2122
, packages = ./packages.dhall
22-
, sources = [ "src/**/*.purs", "test/**/*.purs" ]
23+
, sources = [ "src/**/*.purs", "test/**/*.purs", "bench/**/*.purs" ]
2324
}

0 commit comments

Comments
 (0)