#1/bin/bash

# Clean up debug environment I've got that results in spam into the logs.
unset LIBGL_DEBUG
export vblank_mode=0

i=0
first=0

rm -f before after

while true; do
	# The printout of ministat at the end of the loop may get
	# pipelined and thus take CPU during our next test run, often
	# during the first run of the two.  To avoid systematic bias,
	# flip around which testcase runs first each time.
	if test $first -lt 1; then
		$2 $1 >> before
		$3 $1 >> after
	else
		$3 $1 >> after
		$2 $1 >> before
	fi
	first=$((1-$first))

	# Sometimes it's nice to see the numbers too, so uncomment
	# that.

	# cat before after

	# nuke the data from the first run.  We usually don't want the
	# first run, because that's when we're loading disk cache,
	# warming up the GPU, etc.
	if test $i = 0; then
		rm -f before after
	fi

	# once we've got 3 points each, start running ministat.
	if test $i -gt 1; then
		ministat before after
	fi

	i=$(($i + 1))
done
