in reply to The cost of unchecked best practices
Off topic: Perhaps single char positive character classes should be optimized to be equivalent to a literal character? Perhaps something can be done about single char negative character classes too.
Update: Corion sent me a message saying he thought this was already done in 5.10, so I put it to the test. Indeed, it is.
Test code used: (Same as OP accept avoided extra sub calls)
#!/usr/bin/perl use strict; use warnings; use Benchmark qw( cmpthese ); our $line = ('a' x 500) . ' ' . ('a' x 20); sub code { "use strict; use warnings; $_[0]; 1;" } cmpthese -2, { literal => code(' our $line =~ / a .{1,10} \ /x; '), class => code(' our $line =~ / a .{1,10} [ ] /x; '), class_nodot => code(' our $line =~ / a [^\n]{1,10} [ ] /smx; '), };
>c:\progs\perl588\bin\perl 674979.pl Rate class_nodot class literal class_nodot 2206/s -- -44% -100% class 3908/s 77% -- -100% literal 805341/s 36409% 20507% -- >c:\progs\perl5100\bin\perl 674979.pl Rate class_nodot literal class class_nodot 618394/s -- -12% -13% literal 704734/s 14% -- -1% class 708360/s 15% 1% --
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: The cost of unchecked best practices
by bart (Canon) on Mar 20, 2008 at 20:18 UTC | |
by ikegami (Patriarch) on Mar 21, 2008 at 00:06 UTC |