You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm thinking to use PetitParserDart instead of RegRex in my dart program, since I find it easier to write the code in PetitParserDart for complex rules than regex. But I don't know if the performance is good enough.
So I just write a small test:
import "package:petitparser/petitparser.dart";
const s = "dfsdf 2323 efwe 3345 fewf 9897 dfsdf 2323 efwe 3345 fewf 9897 dfsdf 2323 efwe 3345 fewf 9897 dfsdf 2323 efwe 3345 fewf 9897";
main() {
test(petitTest);
test(regexTest);
}
test(x()) {
var start = new DateTime.now();
for (int i = 0;i < 100000;i++) {
x();
}
var end = new DateTime.now();
print("cost: ${end.millisecondsSinceEpoch - start.millisecondsSinceEpoch} ms");
}
var regexParser = new RegExp(r"\d+");
regexTest() {
for (var m in regexParser.allMatches(s)) {
m.group(0);
}
}
var petitParser = (digit().plus().flatten() | any()).plus();
petitTest() {
petitParser.parse(s).value;
}
The result is:
cost: 924 ms
cost: 959 ms
Seems they have very similar performance. I'm not sure if my test is correct, and I want to get more information about PetitParserDart from you.
Thank you ~
The text was updated successfully, but these errors were encountered:
PetitParser can be fast, depending on what you parse, how you wrote your parser and how you parse. PetitParser is more powerful, as you can have recursion and production actions. Additionally, PetitParser is not limited to strings, you can parse and match any list of objects. PetitParser gets slightly faster over time as the Dart VM starts to JIT its code.
Keep in mind that the semantics of regular expressions and parsing expression grammars are very different. For example, the star() and plus() operators are greedy, consuming as much input as possible. The operators starGreedy() and starLacy() that I recently added can help you there if you need.
Regarding the test you could write it using Parser.matchesSkipping(String) to make it simpler and look more like a regular expression:
final petitParser = digit().plus().flatten();
petitTest() {
for (var m in petitParser.matchesSkipping(s)) {
m;
}
}
I'm thinking to use PetitParserDart instead of RegRex in my dart program, since I find it easier to write the code in PetitParserDart for complex rules than regex. But I don't know if the performance is good enough.
So I just write a small test:
The result is:
Seems they have very similar performance. I'm not sure if my test is correct, and I want to get more information about PetitParserDart from you.
Thank you ~
The text was updated successfully, but these errors were encountered: