diff -r 939c10745a3a -r a10430cb797c progs/catastrophic/catastrophic.dart --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/progs/catastrophic/catastrophic.dart Wed Oct 07 09:08:55 2020 +0100 @@ -0,0 +1,23 @@ +/// A case of catastrophic backtracking in Dart +///--------------------------------------------- +/// example provided by Martin Todorov +/// +/// regex: (a*)*b +/// strings: aa...a +/// +/// run with +/// +/// dart catastrophic.dart n + + +main(List args) { + final n = int.parse(args[0]); + final evilRegex = RegExp("(a*)*b"); + + for(int i = 1; i <= n; i++) { + final toMatch = "a" * i; + final stopwatch = Stopwatch()..start(); + evilRegex.hasMatch(toMatch); + print("$i a's matched in ${stopwatch.elapsed}"); + } +}