VirtualBox

source: kBuild/trunk/src/grep/tests/hash-collision-perf

Last change on this file was 3529, checked in by bird, 3 years ago

Imported grep 3.7 from grep-3.7.tar.gz (sha256: c22b0cf2d4f6bbe599c902387e8058990e1eee99aef333a203829e5fd3dbb342), applying minimal auto-props.

  • Property svn:executable set to *
File size: 2.0 KB
Line 
1#!/bin/sh
2# Test for this performance regression:
3# grep-3.5 and 3.6 would take O(N^2) time for some sets of input regexps.
4
5# Copyright 2020-2021 Free Software Foundation, Inc.
6
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16
17# You should have received a copy of the GNU General Public License
18# along with this program. If not, see <https://www.gnu.org/licenses/>.
19
20. "${srcdir=.}/init.sh"; path_prepend_ ../src
21
22fail=0
23
24: > empty || framework_failure_
25
26# Construct a test case that consumes enough CPU time that we don't
27# have to worry about measurement noise. This first case is searching
28# for digits, which never exhibited a problem with hash collisions.
29n_pat=40000
30while :; do
31 seq $n_pat > in || framework_failure_
32 small_ms=$(LC_ALL=C user_time_ 1 grep --file=in empty) || fail=1
33 test $small_ms -ge 200 && break
34 n_pat=$(expr $n_pat '*' 2)
35done
36
37# Now, search for those same digits mapped to A-J.
38# With the PJW-based hash function, this became O(N^2).
39seq $n_pat | tr 0-9 A-J > in || framework_failure_
40large_ms=$(LC_ALL=C user_time_ 1 grep --file=in empty) || fail=1
41
42# Deliberately recording in an unused variable so it
43# shows up in set -x output, in case this test fails.
44ratio=$(expr "$large_ms" / "$small_ms")
45warn_ ratio=$ratio
46
47# The duration of the latter run must be no more than 10 times
48# that of the former. Using recent versions prior to this fix,
49# this test would fail due to ratios > 800. Using the fixed version,
50# it's common to see a ratio less than 1.
51returns_ 1 expr $small_ms '<' $large_ms / 10 || fail=1
52
53Exit $fail
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette