UserTag benchmark Documentation <<EOD
=head2 [benchmark]

A non-precise benchmark of different iteration options can be done
with the following global UserTag. Place this in a file in the
usertag/ directory in the Interchange root.

At the beginning of the code to check, call

        [benchmark start=1]

to start the measurement. At the end

        [benchmark]

will display the time used. Bear in mind that it is not precise, and
that there may be variation due to system conditions. Also, the longer
the times and the bigger the list, the better the comparison.

To see the system/user breakdown, do:

        [benchmark verbose=1]

In general, "user" time measures Interchange processing time and and
the rest are indicative of the database access overhead, which can vary
widely from database to database.

EOD

UserTag benchmark Order start display
UserTag benchmark AddAttr
UserTag benchmark Routine <<EOR
my $bench_start;
my @bench_times;
sub {
	my ($start, $display, $opt) = @_;
	my @times = times();
	if($start or ! defined $bench_start) {
		$bench_start = 0;
		@bench_times = @times;
		for(@bench_times) {
			$bench_start += $_;
		}
	}
	my $current_total;
	if($display or ! $start) {
		for(@times) {
			$current_total += $_;
		}
        unless ($start) {
            $current_total = sprintf '%.3f', $current_total - $bench_start;
            for(my $i = 0; $i < 4; $i++) {
                $times[$i] = sprintf '%.3f', $times[$i] - $bench_times[$i];
            }
        }
		return $current_total if ! $opt->{verbose};
		return "total=$current_total user=$times[0] sys=$times[1] cuser=$times[2] csys=$times[3]";
	}
	return;
}
EOR
