perf: Improve calibration

Make the loops count depend on the actual calibration_loops/calibration_time
instead of calibration_loops/calibration_max_time.
This avoids having some tests take much less/more than the wanted time per iteration
(I was having some tests taking about 1 second, other taking about 7 seconds when
the ms_per_iteration was 2000)

Spend 0.5-1 times the time wanted for each iteration in calibration, increase the
accuracy of loops count. Just making the loops count be the correct ratio doesn't
guarantee that the iteration time is accurate. By actually measuring iteration
times until it gets greater than 1/4 of the wanted time, the total sum is bound
to be <= the wanted iteration time and last calibration time is between 1/4 and
1/2 of the wanted time, so it should give a very accurate loop count.
This commit is contained in:
Andrea Canciani 2010-08-09 18:47:13 +02:00
parent 046b642db0
commit 7668323649

View file

@ -128,18 +128,17 @@ static unsigned
cairo_perf_calibrate (cairo_perf_t *perf,
cairo_perf_func_t perf_func)
{
cairo_perf_ticks_t calibration0, calibration;
cairo_perf_ticks_t calibration, calibration_max;
unsigned loops, min_loops;
min_loops = 1;
calibration0 = perf_func (perf->cr, perf->size, perf->size, min_loops);
if (perf->fast_and_sloppy) {
calibration = calibration0;
} else {
calibration = 0.01 * cairo_perf_ticks_per_second ();
while (calibration0 < calibration) {
min_loops *= 10;
calibration0 = perf_func (perf->cr, perf->size, perf->size, min_loops);
calibration = perf_func (perf->cr, perf->size, perf->size, min_loops);
if (!perf->fast_and_sloppy) {
calibration_max = perf->ms_per_iteration * 0.0001 / 4 * cairo_perf_ticks_per_second ();
while (calibration < calibration_max) {
min_loops *= 2;
calibration = perf_func (perf->cr, perf->size, perf->size, min_loops);
}
}