Skip to content

Commit b0e7068

Browse files
authored
add npeg
1 parent d634217 commit b0e7068

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

bench.nim

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ proc scan(input: string): int =
4040
inc pos
4141
return -1
4242

43+
import npeg
44+
proc pegs(input: string): int =
45+
let p = peg search:
46+
search <- @({'P', 'p'} * "leasuring")
47+
let r = p.match(input)
48+
return if r.ok: r.matchLen else: -1
49+
4350
proc main =
4451
let inp = readFile("benchdata.txt")
4552
when true:
@@ -63,10 +70,15 @@ proc main =
6370
for i in 1..100:
6471
discard scan(inp)
6572

73+
bench "npeg":
74+
for i in 1..100:
75+
discard pegs(inp)
76+
6677
echo matchLen(inp, bc)
6778
echo re.find(inp, thaRe)+len"pleasuring"
6879
echo find(inp, "pleasuring")+len"pleasuring"
6980
echo lex(inp) # +len"pleasuring"
7081
echo scan(inp) # +len"pleasuring"
82+
echo pegs(inp) # +len"pleasuring"
7183

7284
main()

0 commit comments

Comments
 (0)