#!/usr/bin/perl # # $Id: regex-quantifiers 2592 2003-12-21 00:33:01Z jmates $ # # The author disclaims all copyrights and releases this document into # the public domain. # # Testing of \w{4} versus \w\w\w\w and related in regex. use Benchmark qw(cmpthese); $test = "foo bar aaaa zot"; # test the routines here #&tag; cmpthese( 1000000, { 'short-char' => \&short, 'long-char' => \&long, 'look-sc' => \&looksc, 'look-lc' => \&looklc, 'short-meta' => \&mshort, 'long-meta' => \&mlong, 'lc-miss' => \&lcmiss, 'sc-miss' => \&scmiss, 'nbr-long' => \&nbrlong, 'nbr-short' => \&nbrshort, } ); sub nbrlong { $test =~ /\w\w\w\w/; } sub nbrshort { $test =~ /\w{4}/; } sub lcmiss { $test =~ /(a)\1\1\1\1\1/; } sub scmiss { $test =~ /(a)\1{5}/; } sub mshort { $test =~ /(\w)\1{3}/; } sub mlong { $test =~ /(\w)\1\1\1/; } sub looksc { $test =~ /(?=(a))\1{4}/; } sub looklc { $test =~ /(?=(a))\1\1\1\1/; } sub short { $test =~ /(a)\1{3}/; } sub long { $test =~ /(a)\1\1\1/; } __END__