in reply to Re: regex regexen
in thread regex regexen
#!/usr/bin/perl use strict; use warnings; use Benchmark 'cmpthese'; our $re1 = qr /"([^"\\]|\\.)*"/; our $re2 = qr /"([^"\\]+|\\.)*"/; our $re3 = qr /"[^"\\]*(\\.[^"\\]*)*"/; chomp (our @data = <DATA>); cmpthese -5 => { plain => '/$re1/ for @data', unroll1 => '/$re2/ for @data', unroll2 => '/$re3/ for @data', }; __DATA__ A "red" fish A "red" fish and a "blue" fish The book is called "A 5\" dwarf" A backslash ("\\") and a forwardslash ("/") No delimiters here at all.
The results:
Rate plain unroll1 unroll2 plain 50621/s -- -20% -38% unroll1 63260/s 25% -- -22% unroll2 81507/s 61% 29% --
Abigail
|
|---|