}
}
-function Animator(benchmark)
+function Animator(benchmark, options)
{
this._benchmark = benchmark;
+ this._options = options;
+
this._frameCount = 0;
this._dropFrameCount = 1;
this._measureFrameCount = 3;
this._referenceTime = 0;
this._currentTimeOffset = 0;
- this._estimator = new KalmanEstimator();
+ this._estimator = new KalmanEstimator(60);
}
Animator.prototype =
{
- start: function()
- {
- this._intervalId = setInterval(this.animate.bind(this), 1);
- },
-
timeDelta: function()
{
return this._currentTimeOffset - this._startTimeOffset;
if (!this._frameCount)
this._startTimeOffset = this._currentTimeOffset;
+ ++this._frameCount;
+
// Start measuring after dropping _dropFrameCount frames.
if (this._frameCount == this._dropFrameCount)
this._measureTimeOffset = this._currentTimeOffset;
- ++this._frameCount;
-
// Drop _dropFrameCount frames and measure the average of _measureFrameCount frames.
if (this._frameCount < this._dropFrameCount + this._measureFrameCount)
return true;
var currentFrameRate = Math.floor(1000 / (measureTimeDelta / this._measureFrameCount));
// Use Kalman filter to get a more non-fluctuating frame rate.
- if (this._benchmark.options.estimatedFrameRate)
- currentFrameRate = this._estimator.estimate(measureTimeDelta, currentFrameRate);
+ if (this._options["estimated-frame-rate"])
+ currentFrameRate = this._estimator.estimate(currentFrameRate);
// Adjust the test to reach the desired FPS.
var result = this._benchmark.update(this._currentTimeOffset, this.timeDelta(), currentFrameRate);
- // Stop the animator if the benchmark has finished.
- if (!result && typeof this._intervalId != "undefined")
- clearInterval(this._intervalId);
-
// Start the next drop/measure cycle.
this._frameCount = 0;
- // result may stop the animator if requestAnimationFrame() has been used.
+ // If result == 0, no more requestAnimationFrame() will be invoked.
return result;
},
function Benchmark(options)
{
this._options = options;
- this._method = this._options["method"] || "requestAnimationFrame";
-
- this.options = options;
this._recordInterval = 200;
this._isSampling = false;
var lowValue = -parseInt(this._options["addLimit"]) || 1;
var highValue = parseInt(this._options["removeLimit"]) || 1;
- this._controller = new PIDController(gain, options.frameRate, lowValue, highValue);
+ this._controller = new PIDController(gain, this._options["frame-rate"], lowValue, highValue);
this._sampler = new Sampler(2);
- this._state = new BenchmarkState(this.options.testInterval);
+ this._state = new BenchmarkState(this._options["test-interval"] * 1000);
}
Benchmark.prototype =
// Called from the load event listener or from this.run().
start: function()
{
- if (this._method == "setInterval")
- this._animator.start();
- else
- this._animator.animateLoop();
+ this._animator.animateLoop();
},
// Called from the animator to adjust the complexity of the test.
}
var tuneValue = 0;
- if (!(this._isSampling && this.options.fixTestComplexity)) {
+ if (this._options["complexity"] && !this._options["adaptive-test"]) {
+ // this.tune(0) returns the current complexity of the test.
+ tuneValue = this._options["complexity"] - this.tune(0);
+ }
+ else if (!(this._isSampling && this._options["fix-test-complexity"])) {
// The relationship between frameRate and test complexity is inverse-proportional so we
// need to use the negative of PIDController.tune() to change the complexity of the test.
tuneValue = -this._controller.tune(currentFrameRate, timeDelta / 1000);
// This function is called from the suite controller run-callback when running the benchmark runner.
window.runBenchmark = function(suite, test, options, recordTable, progressBar)
{
- var mergedOptions = Utilities.mergeObjects(options, Utilities.parseParameters());
- window.benchmark = window.benchmarkClient.create(suite, test, mergedOptions, recordTable, progressBar);
+ var benchmarkOptions = { complexity: test.complexity };
+ benchmarkOptions = Utilities.mergeObjects(benchmarkOptions, options);
+ benchmarkOptions = Utilities.mergeObjects(benchmarkOptions, Utilities.parseParameters());
+ window.benchmark = window.benchmarkClient.create(suite, test, benchmarkOptions, recordTable, progressBar);
return window.benchmark.run();
}