From ce898d98d5ff0ffbd988c993d2b3f1e414a6df2a Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sun, 26 Jul 2015 11:04:20 -0700 Subject: [PATCH 2/3] tests: long-pattern-perf: measure user time, not elapsed Measuring user time makes this test less prone to false positive failure, and also lets us use a tighter bound. * tests/long-pattern-perf: Measure elapsed user time rather than wall-clock time, to permit a tighter bound on the ratio of N-to-10N timings. Suggested by Giuseppe Ottaviano. Also, use regexps built from mostly 5-digit numbers, so that the 10:1 ratio applies to lines of "seq" output as well as to total bytes. --- tests/long-pattern-perf | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/tests/long-pattern-perf b/tests/long-pattern-perf index cba6553..c222c02 100755 --- a/tests/long-pattern-perf +++ b/tests/long-pattern-perf @@ -17,8 +17,6 @@ # along with this program. If not, see . . "${srcdir=.}/init.sh"; path_prepend_ ../src -require_timeout_ -require_hi_res_time_ fail=0 @@ -26,25 +24,15 @@ echo x > in || framework_failure_ # We could use seq -s '' (avoiding the tr filter), but I # suspect some version of seq does not honor that option. # Note that we want 10x the byte count (not line count) in the larger file. -seq 5000 | tr -d '\012' > re || framework_failure_ -seq 40000 | tr -d '\012' > re-10x || framework_failure_ +seq 10000 20000 | tr -d '\012' > re || framework_failure_ +seq 10000 100000 | tr -d '\012' > re-10x || framework_failure_ -start=$(hi_res_time_) -grep -f re in; st=$? -stop=$(hi_res_time_) -test $st = 1 || fail=1 +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 30x to avoid false-positives. -# Use an integer; some 'timeout' implementations have trouble with -# floating-point. -n_sec=$( - $AWK 'BEGIN { print 1 + int (30 * ('$stop' - '$start'))}' < /dev/null -) - -# Expect no match, i.e., exit status of 1. Anything else is an error. -timeout $n_sec grep -f re-10x in; st=$? -test $st = 1 || fail=1 +# However, we'll draw the line at 20x to avoid false-positives. +expr $base_ms '<' $b10x_ms / 20 && fail=1 Exit $fail -- 2.3.7