--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/progs/catastrophic.java Sun Aug 21 18:15:53 2016 +0200
@@ -0,0 +1,27 @@
+import java.util.regex.*;
+
+public class catastrophic {
+ public static void main(String[] args) {
+ for (int runs = 0; runs < 2; runs++) {
+ //Pattern pattern = Pattern.compile("(0*)*A");
+ //Pattern pattern = Pattern.compile("a?{20}a{20}");
+
+ // Run from 5 to 25 characters
+ for (int length = 5; length < 25; length++) {
+ Pattern pattern = Pattern.compile("(0*)*A");
+ // Build input of specified length
+ String input = "";
+ for (int i = 0; i < length; i++) { input += "0"; }
+
+ // Measure the average duration of two calls...
+ long start = System.nanoTime();
+ for (int i = 0; i < 2; i++) {
+ pattern.matcher(input).find();
+ }
+ System.out.println(input + ": "
+ + ((System.nanoTime() - start) / 2000000d)
+ + "ms");
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/progs/catastrophic.py Sun Aug 21 18:15:53 2016 +0200
@@ -0,0 +1,12 @@
+#!/usr/bin/env python
+import re
+import sys
+
+cn = sys.argv[1]
+
+r1 = '((a?){%s})' % cn
+r2 = 'a{%s}' % cn
+
+m = re.match(r1 + r2 , "a" * int(cn))
+
+print m.group(0)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/progs/catastrophic.rb Sun Aug 21 18:15:53 2016 +0200
@@ -0,0 +1,23 @@
+# provided by Daniel Baldwin
+
+nums = (1..1000)
+
+#iterate through the nums 1-100
+nums.each do |i|
+
+ start_time = Time.now
+ string = "a" * i
+ re_str = "a?" * i + "+" + "a" * i
+ #create a new regular expression based on current value of i
+
+ re = Regexp.new(re_str)
+
+ re.match(string)
+ #if re.match(string)
+ # puts "matched string a * #{i} with regex #{re}"
+ #else
+ # puts "unmatched string a * #{i} with regex #{re}"
+ #end
+
+ puts "#{i} %.5f" % (Time.now - start_time)
+end
--- a/progs/re.py Sun Aug 21 00:43:31 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,12 +0,0 @@
-#!/usr/bin/env python
-import re
-import sys
-
-cn = sys.argv[1]
-
-r1 = '((a?){%s})' % cn
-r2 = 'a{%s}' % cn
-
-m = re.match(r1 + r2 , "a" * int(cn))
-
-print m.group(0)
--- a/progs/re.rb Sun Aug 21 00:43:31 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,23 +0,0 @@
-# provided by Daniel Baldwin
-
-nums = (1..1000)
-
-#iterate through the nums 1-100
-nums.each do |i|
-
- start_time = Time.now
- string = "a" * i
- re_str = "a?" * i + "+" + "a" * i
- #create a new regular expression based on current value of i
-
- re = Regexp.new(re_str)
-
- re.match(string)
- #if re.match(string)
- # puts "matched string a * #{i} with regex #{re}"
- #else
- # puts "unmatched string a * #{i} with regex #{re}"
- #end
-
- puts "#{i} %.5f" % (Time.now - start_time)
-end