summaryrefslogtreecommitdiffstats
path: root/src/grep/tests/long-pattern-perf
diff options
context:
space:
mode:
Diffstat (limited to 'src/grep/tests/long-pattern-perf')
-rwxr-xr-xsrc/grep/tests/long-pattern-perf42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/grep/tests/long-pattern-perf b/src/grep/tests/long-pattern-perf
new file mode 100755
index 0000000..8151c1a
--- /dev/null
+++ b/src/grep/tests/long-pattern-perf
@@ -0,0 +1,42 @@
+#!/bin/sh
+# grep-2.21 would incur a 100x penalty for 10x increase in regexp length
+
+# Copyright 2015-2021 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../src
+
+fail=0
+
+# This test is susceptible to failure due to differences in
+# system load during the two test runs, so we'll mark it as
+# "expensive", making it less likely to be run by regular users.
+expensive_
+
+echo x > in || framework_failure_
+# Note that we want 10x the byte count (not line count) in the larger file.
+seq 10000 50000 | tr -d '\012' > r || framework_failure_
+cat r r r r r r r r r r > re-10x || framework_failure_
+mv r re || framework_failure_
+
+base_ms=$(user_time_ 1 grep -f re in ) || fail=1
+b10x_ms=$(user_time_ 1 grep -f re-10x in) || fail=1
+
+# Increasing the length of the regular expression by a factor
+# of 10 should cause no more than a 10x increase in duration.
+# However, we'll draw the line at 20x to avoid false-positives.
+returns_ 1 expr $base_ms '<' $b10x_ms / 20 || fail=1
+
+Exit $fail