1(define (check pat str) 2 (write 3 (time 4 (let ([rx (byte-regexp (string->bytes/utf-8 pat))] 5 [in (string->bytes/utf-8 str)]) 6 (let loop ([v #f] [n 100000]) 7 (if (zero? n) 8 v 9 (loop (regexp-match rx in) 10 (sub1 n))))))) 11 (newline)) 12 13;; A smallish backtracking test, more or less: 14(check "ab(?:a*c)*d" "abaacacaaacacaaacd") 15 16;; Relatively realitic workload: 17(define ipv6-hex "[0-9a-fA-F:]*:[0-9a-fA-F:]*") 18(define url-s 19 (string-append 20 "^" 21 "(?:" ; / scheme-colon-opt 22 "([^:/?#]*)" ; | #1 = scheme-opt 23 ":)?" ; \ 24 "(?://" ; / slash-slash-authority-opt 25 "(?:" ; | / user-at-opt 26 "([^/?#@]*)" ; | | #2 = user-opt 27 "@)?" ; | \ 28 "(?:" ; 29 "(?:\\[" ; | / #3 = ipv6-host-opt 30 "(" ipv6-hex ")" ; | | hex-addresses 31 "\\])|" ; | \ 32 "([^/?#:]*)" ; | #4 = host-opt 33 ")?" ; 34 "(?::" ; | / colon-port-opt 35 "([0-9]*)" ; | | #5 = port-opt 36 ")?" ; | \ 37 ")?" ; \ 38 "([^?#]*)" ; #6 = path 39 "(?:\\?" ; / question-query-opt 40 "([^#]*)" ; | #7 = query-opt 41 ")?" ; \ 42 "(?:#" ; / hash-fragment-opt 43 "(.*)" ; | #8 = fragment-opt 44 ")?" ; \ 45 "$")) 46(define rlo "https://racket-lang.org:80x/people.html?check=ok#end") 47(check url-s rlo) 48 49;; A test of scanning a byte string to look for the letter "b" 50;; (where a tight loop in C is likely to win): 51(check "a*b" (make-string 1024 #\a)) 52