File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed
Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff 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+
4350proc 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
7284main ()
You can’t perform that action at this time.
0 commit comments