Skip to content

Commit

Permalink
added series object
Browse files Browse the repository at this point in the history
  • Loading branch information
g-w committed Nov 17, 2010
1 parent 7b1a861 commit 1da1523
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 3 deletions.
9 changes: 7 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,19 @@ <h1>HbbTV - Javascript Benchmarks</h1>

<script type="text/javascript" src="js/helpers.js"></script>
<script type="text/javascript" src="js/test.js"></script>
<script type="text/javascript" src="js/series.js"></script>

<script type="text/javascript" src="tests/dummy.js"></script>

<script type="text/javascript">
window.addEventListener( "load", function() {
var t = TestCase.create("dummy");
console.log(t.start());
console.log(t.result());
var ts = new TestSeries(t);
ts.run(10, function () {
console.log(ts.max());
console.log(ts.min());
console.log(ts.avg());
});
}, false );

</script>
Expand Down
2 changes: 1 addition & 1 deletion js/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
return destination;
};

Array.avg = function () {
Array.prototype.avg = function () {
var sum = 0.0;
for (var i = 0; i < this.length; i++) {
sum += this[i]; // Assumes that this is of type <Integer[]>
Expand Down
60 changes: 60 additions & 0 deletions js/series.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
(function () {

var TestSeries = window.TestSeries = function (testCase) {

this._testCase = testCase;

this._maxValue = undefined;
this._minValue = undefined;

this.results = [];
};

Object.extend(TestSeries.prototype, {
run: function (c, callback) {
var that = this;
var count = c;

var sample = function () {
if (that._testCase.start()) {
var result = that._testCase.result();
that.results.push(result);
that._updateMax(result);
that._updateMin(result);
} else {
this._errorCount += 1;
}

count--;
if(count >= 0) {
setTimeout(sample, 1);
} else {
setTimeout(callback, 1);
}
};

sample();
},

max: function () {
return this._maxValue;
},

min: function () {
return this._minValue;
},

avg: function () {
return this.results.avg();
},

_updateMax: function (result) {
this._maxValue = (this._maxValue === undefined || result > this._maxValue) ? result : this._maxValue;
},

_updateMin: function (result) {
this._minValue = (this._minValue === undefined || result < this._minValue) ? result : this._minValue;
}
})

})();

0 comments on commit 1da1523

Please sign in to comment.