execSync method

PerfTestOne execSync({
  1. int? maxLaps,
  2. Duration? maxSpan,
})

Actual test execution (synchronous)

Implementation

PerfTestOne execSync({int? maxLaps, Duration? maxSpan}) {
  stopwatch.reset();

  final testProcSync = this.testProcSync;

  if (testProcSync == null) {
    return this;
  }

  isOutLaps = (maxLaps == null);
  num spanAdjustment = 1.0;

  if (maxLaps != null) {
    laps = maxLaps;

    for (var i = 0; i < maxLaps; i++) {
      if (!isMyStopwatch) {
        stopwatch.start();
      }
      testProcSync(this, i);
      stopwatch.stop(); // no need to spend time on checking isMyStopwatch
    }
  } else if (maxSpan != null) {
    laps = 0;
    final maxMilliseconds = maxSpan.inMilliseconds;

    for (; stopwatch.elapsedMilliseconds < maxMilliseconds; laps++) {
      if (!isMyStopwatch) {
        stopwatch.start();
      }
      testProcSync(this, laps);
      stopwatch.stop(); // no need to spend time on checking isMyStopwatch
    }
    if (maxMilliseconds == 0) {
      spanAdjustment = 0;
    } else {
      spanAdjustment = stopwatch.elapsedMilliseconds / maxMilliseconds;
    }
  }

  _setSpan(maxSpan, spanAdjustment);
  _output();

  return this;
}