mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-15 23:55:03 +03:00
Allow unit tests to be performance tested. Add an example script to generate @rx vs @pm tests.
97 lines
1.6 KiB
Perl
Executable File
97 lines
1.6 KiB
Perl
Executable File
#!@PERL@
|
|
#
|
|
# Generates a test file for comparing @rx and @pm speed.
|
|
#
|
|
use strict;
|
|
use Regexp::Assemble;
|
|
|
|
|
|
my $MIN = 1;
|
|
my $MAX = 5000;
|
|
my $INC = 250;
|
|
my $ITERATIONS = 10000;
|
|
my $MINSTRLEN = 2;
|
|
my $MAXSTRLEN = 8;
|
|
|
|
my $last = rndstr();
|
|
my @param = ($last);
|
|
my $i=$MIN;
|
|
while ($i <= $MAX) {
|
|
my $ra = Regexp::Assemble->new;
|
|
$ra->add(@param);
|
|
|
|
printf (
|
|
"# rx: %6d\n".
|
|
"{\n".
|
|
" comment => \"%6d item(s)\",\n".
|
|
" type => \"op\",\n".
|
|
" name => \"rx\",\n".
|
|
" param => qr/^(?:%s)\$/,\n".
|
|
" input => \"%s\",\n".
|
|
" ret => 1,\n".
|
|
" iterations => %d,\n".
|
|
"},\n",
|
|
$i,
|
|
$i,
|
|
join('|', @param),
|
|
$last,
|
|
$ITERATIONS,
|
|
);
|
|
|
|
printf (
|
|
"# rx-optimized: %6d\n".
|
|
"{\n".
|
|
" comment => \"%6d item(s)\",\n".
|
|
" type => \"op\",\n".
|
|
" name => \"rx\",\n".
|
|
" param => qr/^(?:%s)\$/,\n".
|
|
" input => \"%s\",\n".
|
|
" ret => 1,\n".
|
|
" iterations => %d,\n".
|
|
"},\n",
|
|
$i,
|
|
$i,
|
|
$ra->as_string,
|
|
$last,
|
|
$ITERATIONS,
|
|
);
|
|
|
|
printf (
|
|
"# pm: %6d\n".
|
|
"{\n".
|
|
" comment => \"%6d item(s)\",\n".
|
|
" type => \"op\",\n".
|
|
" name => \"pm\",\n".
|
|
" param => \"%s\",\n".
|
|
" input => \"%s\",\n".
|
|
" ret => 1,\n".
|
|
" iterations => %d,\n".
|
|
"},\n",
|
|
$i,
|
|
$i,
|
|
join(' ', @param),
|
|
$last,
|
|
$ITERATIONS,
|
|
);
|
|
|
|
$i = ($i == 1) ? $INC : $i + $INC;
|
|
|
|
while (@param < $i) {
|
|
unshift @param, rndstr();
|
|
}
|
|
}
|
|
|
|
sub rndstr {
|
|
my @c=('a'..'z','0'..'9','_');
|
|
my $rndstr;
|
|
my $max = int(rand($MAXSTRLEN - $MINSTRLEN)) + $MINSTRLEN;
|
|
foreach (1 .. $max) {
|
|
$rndstr .= $c[rand @c];
|
|
}
|
|
# We need a string that is not in another string for "last"
|
|
if ($last =~ m/$rndstr/) {
|
|
$rndstr = rndstr();
|
|
}
|
|
return $rndstr;
|
|
}
|