Skip to content

Commit b9253e7

Browse files
committed
Clarify sample indexing in main.js
Use named constants to index into the `samples` data, instead of inscrutable `samples[1][i]` etc. Use `sampleTimeIndex` etc for values used to index into `samples` data. Use `processedSampleTimeIndex` etc for values used to build `controllerSamples`.
1 parent d868502 commit b9253e7

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

MotionMark/tests/resources/main.js

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ Sampler = Utilities.createClass(
5959
}
6060
});
6161

62+
const sampleTimeIndex = 0;
63+
const sampleComplexityIndex = 1;
64+
const sampleFrameLengthEstimateIndex = 2;
65+
6266
Controller = Utilities.createClass(
6367
function(benchmark, options)
6468
{
@@ -136,7 +140,7 @@ Controller = Utilities.createClass(
136140
if (this._intervalEndTimestamp) {
137141
var durations = [];
138142
for (var i = Math.max(this._intervalStartIndex, 1); i < sampleCount; ++i) {
139-
durations.push(this._sampler.samples[0][i] - this._sampler.samples[0][i - 1]);
143+
durations.push(this._sampler.samples[sampleTimeIndex][i] - this._sampler.samples[sampleTimeIndex][i - 1]);
140144
}
141145
var filteredDurations = this.filterOutOutliers(durations);
142146
if (filteredDurations.length > 0)
@@ -164,7 +168,7 @@ Controller = Utilities.createClass(
164168
} else {
165169
this.registerFrameTime(lastFrameLength);
166170
if (this.intervalHasConcluded(timestamp)) {
167-
var intervalStartTimestamp = this._sampler.samples[0][this._intervalStartIndex];
171+
var intervalStartTimestamp = this._sampler.samples[sampleTimeIndex][this._intervalStartIndex];
168172
intervalAverageFrameLength = this._measureAndResetInterval(timestamp);
169173
if (this._isFrameLengthEstimatorEnabled) {
170174
this._frameLengthEstimator.sample(intervalAverageFrameLength);
@@ -223,28 +227,34 @@ Controller = Utilities.createClass(
223227

224228
_processControllerSamples: function()
225229
{
230+
const processedSampleTimeIndex = 0;
231+
const processedSampleComplexityIndex = 1;
232+
const processedSampleFrameLengthIndex = 2;
233+
const processedSampleSmoothedFrameLengthIndex = 3;
234+
226235
var controllerSamples = new SampleData;
227-
controllerSamples.addField(Strings.json.time, 0);
228-
controllerSamples.addField(Strings.json.complexity, 1);
229-
controllerSamples.addField(Strings.json.frameLength, 2);
230-
controllerSamples.addField(Strings.json.smoothedFrameLength, 3);
236+
controllerSamples.addField(Strings.json.time, processedSampleTimeIndex);
237+
controllerSamples.addField(Strings.json.complexity, processedSampleComplexityIndex);
238+
239+
controllerSamples.addField(Strings.json.frameLength, processedSampleFrameLengthIndex);
240+
controllerSamples.addField(Strings.json.smoothedFrameLength, processedSampleSmoothedFrameLengthIndex);
231241

232242
var samples = this._sampler.samples;
233-
samples[0].forEach(function(timestamp, i) {
243+
samples[sampleTimeIndex].forEach(function(timestamp, i) {
234244
var sample = controllerSamples.createDatum();
235245
controllerSamples.push(sample);
236246

237247
// Represent time in milliseconds
238248
controllerSamples.setFieldInDatum(sample, Strings.json.time, timestamp - this._startTimestamp);
239-
controllerSamples.setFieldInDatum(sample, Strings.json.complexity, samples[1][i]);
249+
controllerSamples.setFieldInDatum(sample, Strings.json.complexity, samples[sampleComplexityIndex][i]);
240250

241251
if (i == 0)
242252
controllerSamples.setFieldInDatum(sample, Strings.json.frameLength, 1000/this._targetFrameRate);
243253
else
244-
controllerSamples.setFieldInDatum(sample, Strings.json.frameLength, timestamp - samples[0][i - 1]);
254+
controllerSamples.setFieldInDatum(sample, Strings.json.frameLength, timestamp - samples[sampleTimeIndex][i - 1]);
245255

246-
if (samples[2][i] != -1)
247-
controllerSamples.setFieldInDatum(sample, Strings.json.smoothedFrameLength, samples[2][i]);
256+
if (samples[sampleFrameLengthEstimateIndex][i] != -1)
257+
controllerSamples.setFieldInDatum(sample, Strings.json.smoothedFrameLength, samples[sampleFrameLengthEstimateIndex][i]);
248258
}, this);
249259

250260
return controllerSamples;
@@ -544,7 +554,7 @@ RampController = Utilities.createSubclass(Controller,
544554
if (frameLengthAtMaxComplexity < this.frameLengthRampLowerThreshold)
545555
this._possibleMaximumComplexity = Math.floor(Utilities.lerp(Utilities.progressValue(this.frameLengthRampLowerThreshold, frameLengthAtMaxComplexity, this._lastTierFrameLength), this._maximumComplexity, this._lastTierComplexity));
546556
// If the regression doesn't fit the first segment at all, keep the minimum bound at 1
547-
if ((timestamp - this._sampler.samples[0][this._sampler.sampleCount - regression.n1]) / this._currentRampLength < .25)
557+
if ((timestamp - this._sampler.samples[sampleTimeIndex][this._sampler.sampleCount - regression.n1]) / this._currentRampLength < .25)
548558
this._possibleMinimumComplexity = 1;
549559

550560
this._minimumComplexityEstimator.sample(this._possibleMinimumComplexity);
@@ -575,12 +585,12 @@ RampController = Utilities.createSubclass(Controller,
575585

576586
_getComplexity: function(samples, i)
577587
{
578-
return samples[1][i];
588+
return samples[sampleComplexityIndex][i];
579589
},
580590

581591
_getFrameLength: function(samples, i)
582592
{
583-
return samples[0][i] - samples[0][i - 1];
593+
return samples[sampleTimeIndex][i] - samples[sampleTimeIndex][i - 1];
584594
},
585595

586596
processSamples: function(results)

0 commit comments

Comments
 (0)