yhirose / cpp-peglib

A single file C++ header-only PEG (Parsing Expression Grammars) library
MIT License
884 stars 112 forks source link

Benchmarking grammar ? #125

Closed sasq64 closed 3 years ago

sasq64 commented 3 years ago

Is there a way to benchmark your grammar? To see if you have defined rules in a non-optimal way that causes peglib to do unnecessary work ?

yhirose commented 3 years ago

@sasq64, there isn't. I think the performance depend on not only grammar, but also particular context of source text. The only thing that cpp-peglib checks is to detect left recursive grammar that could cause infinite loop. Is there any good algorithm or tool to benchmark regular expression grammar, so that we could apply it to PEG? Thanks!

sasq64 commented 3 years ago

I was thinking maybe recording how much the parse has to backtrack, or parse the same bit of source multiple times. I guess I could implement that myself with the trace callbacks ? Then form a histogram on which rules that where evaluated the most...

yhirose commented 3 years ago

@sasq64, sounds fantactic! Only thing that I request you is to make sure that no extra performance const should be added when trace callbacks are not set.

yhirose commented 3 years ago

@yhirose, I'll close it for now. Please let me know when you work on that.

asmwarrior commented 3 years ago

@sasq64, sounds fantactic! Only thing that I request you is to make sure that no extra performance const should be added when trace callbacks are not set.

Typo: const should be cost.