File: benchmark

package info (click to toggle)
shoop 0.1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 328 kB
  • ctags: 41
  • sloc: sh: 1,138; makefile: 209; perl: 44
file content (84 lines) | stat: -rwxr-xr-x 1,614 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/sh -e
# Benchmark suite (based on shoop/regress)
#
# LGPL copyright 2000 by Adam Heath <doogie@debian.org>

SHELL=$(basename ${SHELL:-bash})

trap '[ "$tmp" ] && rm -f $tmp; exit' 2
# Call this function to benchmark something.
prep() {
	if [ "$_bmprep_" ];then
		_bmprep_="$_bmprep_;$@"
	else
		_bmprep_="$@"
	fi
}
prepsave() {
	eval _bmprep_$1=\"$_bmprep_\"
}
preprestore() {
	eval _bmprep_=\"\$_bmprep_\; \$_bmprep_$1\"
}
prepclear() {
	_bmprep_=""
}

bmcount() {
	ITERATIONS=$1
}

bm () {

	local name=$1 message=$2; shift 2
	if eval [ -z \"\$_bms_$name\" ];then
		eval "_bm_$name () { benchmark $ITERATIONS \"$message\" \"$_bmprep_\" \"$@\"; }"
		eval _bms_$name=1
		_bmtest_="$_bmtest_ $name"
		unset _bmprep_
		_bmcount_=$(expr $_bmcount_ + 1)
	fi

}

# Call this function last say how many tests you should have run.
run () {
	benchmark() {
		local count=$1 message=$2 prep=$3
		shift 3
		local script="$@"
		if [ "$count" = done ]; then
			return
		fi
		seq="$(seq -s ' ' 1 $count)"
		tmp=$(mktemp foo.XXXXXX)
		echo -ne "\t    : [$count] ($SHELL) $message\r"
		/usr/bin/time -o $tmp -f "%E" $SHELL -c "
				$prep;
				for a in $seq; do
					echo -n \$a;$script;
				done
			" >/dev/null 2>&1 || true
		cat $tmp|egrep -v '^Command ((stopped|terminated) by signal|exited with non-zero status) [0-9]*$'
		rm -f $tmp
	}
	if [ "$1" ]; then
		_bmtest_="$@"
	fi
	for a in $_bmtest_;do
		eval _bm_$a
	done
}

if [ "$1" ]; then
	_bmcount_=0
	while [ $# -gt 0 ]; do
		spoke=""
		echo -n "Please wait.  Getting benchmark scripts .. "

		. $1
		echo "done(got $_bmcount_ scripts)."
		run $2
		shift 2
	done
fi