bench_common: add a time limit
authorJean Privat <jean@pryen.org>
Wed, 23 Mar 2016 20:25:32 +0000 (16:25 -0400)
committerJean Privat <jean@pryen.org>
Wed, 23 Mar 2016 20:28:52 +0000 (16:28 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

benchmarks/bench_common.sh

index 32055bd..c7dad6d 100644 (file)
@@ -18,6 +18,9 @@
 # Number of times a command must be run with bench_command
 count=1
 
+# User time limit (in second) before a command is aborted
+usertimelimit=120
+
 # Common functions for all the bench scripts
 
 # Run a single command multiple time and store the execution times
@@ -46,7 +49,10 @@ function bench_command()
 
        # Execute the commands $count times
        for i in `seq 1 "$count"`; do
-               /usr/bin/time -f "%U" -o "$timeout" -a "$@" > $outputopts 2>&1 || { failed=true; die "$1: failed"; }
+               (
+                       ulimit -t "$usertimelimit" 2> /dev/null
+                       /usr/bin/time -f "%U" -o "$timeout" -a "$@" > $outputopts 2>&1
+               ) || { err=$?; failed=true; die "$1: failed with $err"; }
                echo -n "$i. "
                tail -n 1 "$timeout"
        done