diff --git a/js/benchmarks/BenchPress.js b/js/benchmarks/BenchPress.js index 05b1d8364633..dfe51f9e9799 100644 --- a/js/benchmarks/BenchPress.js +++ b/js/benchmarks/BenchPress.js @@ -24,27 +24,27 @@ function randInit() function rand() { - this.seed = (( this.seed * 1309) + 13849) & 0xffff; - return this.seed; + this.seed = (( this.seed * 1309) + 13849) & 0xffff; + return this.seed; } function testRand() { - this.randInit(); - if ((this.rand() != 22896) || - (this.rand() != 34761) || - (this.rand() != 34014) || - (this.rand() != 39231) || - (this.rand() != 52540) || - (this.rand() != 41445) || - (this.rand() != 1546) || - (this.rand() != 5947) || - (this.rand() != 65224)) { - this.error("Random number generator"); - } + this.randInit(); + if ((this.rand() != 22896) || + (this.rand() != 34761) || + (this.rand() != 34014) || + (this.rand() != 39231) || + (this.rand() != 52540) || + (this.rand() != 41445) || + (this.rand() != 1546) || + (this.rand() != 5947) || + (this.rand() != 65224)) { + this.error("Random number generator"); + } } function unimplemented() { - print(""); + print(""); } @@ -66,36 +66,36 @@ AbstractBenchmark.Vect = new Array(10000); /********** AbstractSortBenchmark **********/ function checkArray(a) { - var lastIndex, i; + var lastIndex, i; - /* Note: sort benchmarks use 1-based indexing */ - lastIndex = a.length - 1; - if ((a[1] != this.littlest) || (a[lastIndex] != this.biggest)) { - this.error("Sort Benchmark: Array is not sorted"); - return; - } - for (i = 2; i <= lastIndex; i++) { - if (a[i - 1] > a[i]) { - this.error("Sort Benchmark: Array is not sorted"); - return; - } - } + /* Note: sort benchmarks use 1-based indexing */ + lastIndex = a.length - 1; + if ((a[1] != this.littlest) || (a[lastIndex] != this.biggest)) { + this.error("Sort Benchmark: Array is not sorted"); + return; + } + for (i = 2; i <= lastIndex; i++) { + if (a[i - 1] > a[i]) { + this.error("Sort Benchmark: Array is not sorted"); + return; + } + } } function randomArray(arraySize) { - var a; - var i, val; - this.randInit(); - a = new Array(arraySize + 1); /* extra for 1-based indexing */ - this.biggest = -10000; - this.littlest = 10000; - for (i = 1; i <= arraySize; i++) { - val = this.rand(); - a[i] = val; - if (val > this.biggest) this.biggest = val; - if (val < this.littlest) this.littlest = val; - } - return a; + var a; + var i, val; + this.randInit(); + a = new Array(arraySize + 1); /* extra for 1-based indexing */ + this.biggest = -10000; + this.littlest = 10000; + for (i = 1; i <= arraySize; i++) { + val = this.rand(); + a[i] = val; + if (val > this.biggest) this.biggest = val; + if (val < this.littlest) this.littlest = val; + } + return a; } function AbstractSortBenchmark() @@ -112,20 +112,20 @@ AbstractSortBenchmark.prototype = new AbstractBenchmark; function sieve(flags, flagsSize) { - var primeCount = 0; + var primeCount = 0; - for (var i = 0; i <= flagsSize; i++) { - flags[i] = true; - } - for (var i = 2; i <= flagsSize; i++) { - if (flags[i]) { - primeCount++; - for (var k = i + i; k <= flagsSize; k = k + i) { - flags[k] = false; /* k is not prime */ - } - } - } - return primeCount; + for (var i = 0; i <= flagsSize; i++) { + flags[i] = true; + } + for (i = 2; i <= flagsSize; i++) { + if (flags[i]) { + primeCount++; + for (var k = i + i; k <= flagsSize; k = k + i) { + flags[k] = false; /* k is not prime */ + } + } + } + return primeCount; } function SieveBenchmark_run() @@ -155,42 +155,42 @@ function Ball() function initializeFor(bm) { - this.x = bm.rand() % 500; + this.x = bm.rand() % 500; this.y = bm.rand() % 500; this.xVel = (bm.rand() % 300) - 150; - this.yVel = (bm.rand() % 300) - 150; - return this; + this.yVel = (bm.rand() % 300) - 150; + return this; } function bounce() { - var xLimit = 500; - var yLimit = 500; - var bounced = false; + var xLimit = 500; + var yLimit = 500; + var bounced = false; - this.x = this.x + this.xVel; - this.y = this.y + this.yVel; - if (this.x > xLimit) { - this.x = xLimit; - this.xVel = 0 - Math.abs(this.xVel); - bounced = true; - } - if (this.x < 0) { - this.x = 0; - this.xVel = Math.abs(this.xVel); - bounced = true; - } - if (this.y > yLimit) { - this.y = yLimit; - this.yVel = 0 - Math.abs(this.yVel); - bounced = true; - } - if (this.y < 0) { - this.y = 0; - this.yVel = Math.abs(this.yVel); - bounced = true; - } - return bounced; + this.x = this.x + this.xVel; + this.y = this.y + this.yVel; + if (this.x > xLimit) { + this.x = xLimit; + this.xVel = 0 - Math.abs(this.xVel); + bounced = true; + } + if (this.x < 0) { + this.x = 0; + this.xVel = Math.abs(this.xVel); + bounced = true; + } + if (this.y > yLimit) { + this.y = yLimit; + this.yVel = 0 - Math.abs(this.yVel); + bounced = true; + } + if (this.y < 0) { + this.y = 0; + this.yVel = Math.abs(this.yVel); + bounced = true; + } + return bounced; } function BounceBenchmark() @@ -201,38 +201,38 @@ BounceBenchmark.prototype = new AbstractBenchmark; function BounceBenchmark_run() { - var ballCount = 100; - var balls; - var bounces = 0; - var i, j; - this.randInit(); - balls = new Array(ballCount); - for (i = 0; i < ballCount; i++) { - balls[i] = (new Ball()).initializeFor(this); - } - for (i = 0; i < 10; i++) { - for (j = 0; j < ballCount; j++) { - if (balls[j].bounce()) bounces++; - } - } - if (bounces != 268) this.error("BounceBenchmark " + bounces); + var ballCount = 100; + var balls; + var bounces = 0; + var i, j; + this.randInit(); + balls = new Array(ballCount); + for (i = 0; i < ballCount; i++) { + balls[i] = (new Ball()).initializeFor(this); + } + for (i = 0; i < 10; i++) { + for (j = 0; j < ballCount; j++) { + if (balls[j].bounce()) bounces++; + } + } + if (bounces != 268) this.error("BounceBenchmark " + bounces); } /********** NestedForLoopBenchmark **********/ function NestedForLoopBenchmark_run() { - var sum, i, j; + var sum, i, j; - sum = 0; - for (i = 1000; i > 0; i--) { - for (j = 100; j > 0; j--) { - sum = sum + 1; - } - } - if (sum != 100000) { - this.error("NestedForLoopBenchmark"); - } + sum = 0; + for (i = 1000; i > 0; i--) { + for (j = 100; j > 0; j--) { + sum = sum + 1; + } + } + if (sum != 100000) { + this.error("NestedForLoopBenchmark"); + } } function NestedForLoopBenchmark() @@ -245,21 +245,21 @@ NestedForLoopBenchmark.prototype = new AbstractBenchmark; function NestedWhileLoopBenchmark_run() { - var sum, i, j; + var sum, i, j; - sum = 0; - i = 1000; - while (i > 0) { - j = 100; - while (j > 0) { - sum = sum + 1; - j--; - } - i--; - } - if (sum != 100000) { - this.error("NestedWhileLoopBenchmark"); - } + sum = 0; + i = 1000; + while (i > 0) { + j = 100; + while (j > 0) { + sum = sum + 1; + j--; + } + i--; + } + if (sum != 100000) { + this.error("NestedWhileLoopBenchmark"); + } } function NestedWhileLoopBenchmark() @@ -272,106 +272,106 @@ NestedWhileLoopBenchmark.prototype = new AbstractBenchmark; function PermBenchmark() { - this.count = 0; - this.v = 0; - this.run = PermBenchmark_run; - this.permute = permute; - this.swap = swap; + this.count = 0; + this.v = 0; + this.run = PermBenchmark_run; + this.permute = permute; + this.swap = swap; } PermBenchmark.prototype = new AbstractBenchmark; function swap(i, j) { - var tmp = this.v[i]; - this.v[i] = this.v[j]; - this.v[j] = tmp; + var tmp = this.v[i]; + this.v[i] = this.v[j]; + this.v[j] = tmp; } function permute(n) { var i; - this.count++; - if (n != 1) { - this.permute(n - 1); - for (i = n - 1; i > 0; i--) { - this.swap(n, i); - this.permute(n - 1); - this.swap(n, i); - } - } + this.count++; + if (n != 1) { + this.permute(n - 1); + for (i = n - 1; i > 0; i--) { + this.swap(n, i); + this.permute(n - 1); + this.swap(n, i); + } + } } function PermBenchmark_run() { - this.count = 0; - this.v = new Array(8); /* extra for 1-based indexing */ - this.permute(7); - if (this.count != 8660) { - this.error("PermBenchmark"); - } + this.count = 0; + this.v = new Array(null,null,null,null,null,null,null,null); /* extra for 1-based indexing */ + this.permute(7); + if (this.count != 8660) { + this.error("PermBenchmark"); + } } /********** QueensBenchmark **********/ function QueensBenchmark() { - this.freeRows = null; - this.freeMajs = null; - this.freeMins = null; - this.qrows = null; - this.run = QueensBenchmark_run; - this.placeQueen = placeQueen; - this.doQueens = doQueens; + this.freeRows = null; + this.freeMajs = null; + this.freeMins = null; + this.qrows = null; + this.run = QueensBenchmark_run; + this.placeQueen = placeQueen; + this.doQueens = doQueens; } QueensBenchmark.prototype = new AbstractBenchmark; function placeQueen(col) { - for (var row = 1; row <= 8; row++) { - if (this.freeRows[row] && this.freeMajs[(col + row) - 1] - && this.freeMins[(col - row) + 7]) { - this.qrows[col] = row; - this.freeRows[row] = false; - this.freeMajs[(col + row) - 1] = false; - this.freeMins[(col - row) + 7] = false; - if (col == 8) return true; - if (this.placeQueen(col + 1)) return true; - this.freeRows[row] = true; - this.freeMajs[(col + row) - 1] = true; - this.freeMins[(col - row) + 7] = true; - } - } - return false; + for (var row = 1; row <= 8; row++) { + if (this.freeRows[row] && this.freeMajs[(col + row) - 1] + && this.freeMins[(col - row) + 7]) { + this.qrows[col] = row; + this.freeRows[row] = false; + this.freeMajs[(col + row) - 1] = false; + this.freeMins[(col - row) + 7] = false; + if (col == 8) return true; + if (this.placeQueen(col + 1)) return true; + this.freeRows[row] = true; + this.freeMajs[(col + row) - 1] = true; + this.freeMins[(col - row) + 7] = true; + } + } + return false; } function doQueens() { - var i; + var i; - /* allocate extra element in each array for 1-based indexing */ - this.freeRows = new Array(9); - for (i = 8; i > 0; i--) { - this.freeRows[i] = true; - } - this.freeMajs = new Array(16); - for (i = 15; i > 0; i--) { - this.freeMajs[i] = true; - } - this.freeMins = new Array(16); - for (i = 15; i > 0; i--) { - this.freeMins[i] = true; - } - this.qrows = new Array(9); - for (i = 8; i > 0; i--) { - this.qrows[i] = -1; - } - if (!this.placeQueen(1)) this.error("QueensBenchmark"); + /* allocate extra element in each array for 1-based indexing */ + this.freeRows = new Array(9); + for (i = 8; i > 0; i--) { + this.freeRows[i] = true; + } + this.freeMajs = new Array(16); + for (i = 15; i > 0; i--) { + this.freeMajs[i] = true; + } + this.freeMins = new Array(16); + for (i = 15; i > 0; i--) { + this.freeMins[i] = true; + } + this.qrows = new Array(9); + for (i = 8; i > 0; i--) { + this.qrows[i] = -1; + } + if (!this.placeQueen(1)) this.error("QueensBenchmark"); } function QueensBenchmark_run() { - for (var i = 10; i > 0; i--) - this.doQueens(); + for (var i = 10; i > 0; i--) + this.doQueens(); } /********** QuicksortBenchmark **********/ @@ -385,32 +385,32 @@ QuicksortBenchmark.prototype = new AbstractSortBenchmark; function sort(a, l, r) { - var i, j, pivot, temp; + var i, j, pivot, temp; - i = l; - j = r; - pivot = a[Math.floor((l + r) / 2)]; - while (i <= j) { - while (a[i] < pivot) i++; - while (pivot < a[j]) j--; - if (i <= j) { - temp = a[i]; - a[i] = a[j]; - a[j] = temp; - i++; - j--; - } - } - if (l < j) this.sort(a, l, j); - if (i < r) this.sort(a, i, r); + i = l; + j = r; + pivot = a[Math.floor((l + r) / 2)]; + while (i <= j) { + while (a[i] < pivot) i++; + while (pivot < a[j]) j--; + if (i <= j) { + temp = a[i]; + a[i] = a[j]; + a[j] = temp; + i++; + j--; + } + } + if (l < j) this.sort(a, l, j); + if (i < r) this.sort(a, i, r); } function QuicksortBenchmark_run() { - var v; - v = this.randomArray(1000); - this.sort(v, 1, 1000); - this.checkArray(v); + var v; + v = this.randomArray(1000); + this.sort(v, 1, 1000); + this.checkArray(v); } @@ -425,37 +425,37 @@ RecurseBenchmark.prototype = new AbstractBenchmark; function recurse(n) { - if (n > 0) { - this.recurse(n - 1); - this.recurse(n - 1); - } + if (n > 0) { + this.recurse(n - 1); + this.recurse(n - 1); + } } function RecurseBenchmark_run() { - this.recurse(14); + this.recurse(14); } /********** BubbleSortBenchmark **********/ function bubbleSort(a) { - var top, i, curr, next; + var top, i, curr, next; - top = a.length - 1; - while (top > 1) { - i = 1; - while (i < top) { - curr = a[i]; - next = a[i + 1]; - if (curr > next) { - a[i] = next; - a[i + 1] = curr; - } - i++; - } - top--; - } + top = a.length - 1; + while (top > 1) { + i = 1; + while (i < top) { + curr = a[i]; + next = a[i + 1]; + if (curr > next) { + a[i] = next; + a[i + 1] = curr; + } + i++; + } + top--; + } } function BubbleSortBenchmark() @@ -467,10 +467,10 @@ BubbleSortBenchmark.prototype = new AbstractSortBenchmark; function BubbleSortBenchmark_run() { - var a; - a = this.randomArray(250); - this.bubbleSort(a); - this.checkArray(a); + var a; + a = this.randomArray(250); + this.bubbleSort(a); + this.checkArray(a); } @@ -483,62 +483,62 @@ function IncrementAllBenchmark() IncrementAllBenchmark.prototype = new AbstractBenchmark; function IncrementAllBenchmark_run() { - var oldVal, i; + var oldVal, i; - oldVal = AbstractBenchmark.Vect[1]; - for (i = AbstractBenchmark.Vect.length - 1; i >= 0; i--) { - AbstractBenchmark.Vect[i] = AbstractBenchmark.Vect[i] + 1; - } - if (AbstractBenchmark.Vect[1] != (oldVal + 1)) { - this.error("IncrementAllBenchmark"); - } + oldVal = AbstractBenchmark.Vect[1]; + for (i = AbstractBenchmark.Vect.length - 1; i >= 0; i--) { + AbstractBenchmark.Vect[i] = AbstractBenchmark.Vect[i] + 1; + } + if (AbstractBenchmark.Vect[1] != (oldVal + 1)) { + this.error("IncrementAllBenchmark"); + } } /********** MMIntBenchmark **********/ function IntegerMatrix(rowCount, columnCount) { - this.rows = rowCount; - this.columns = columnCount; - this.data = new Array(rowCount); - for (var i = rowCount - 1; i >= 0; i--) { - this.data[i] = new Array(columnCount); - } - this.fillFor = IntegerMatrix_fillFor; - this.dotProduct = IntegerMatrix_dotProduct; - this.multiplyBy = IntegerMatrix_multiplyBy; + this.rows = rowCount; + this.columns = columnCount; + this.data = new Array(rowCount); + for (var i = rowCount - 1; i >= 0; i--) { + this.data[i] = new Array(columnCount); + } + this.fillFor = IntegerMatrix_fillFor; + this.dotProduct = IntegerMatrix_dotProduct; + this.multiplyBy = IntegerMatrix_multiplyBy; } function IntegerMatrix_fillFor(bm) { - for (var i = this.rows - 1; i >= 0; i--) { - for (var j = this.columns - 1; j >= 0; j--) { - this.data[i][j] = (bm.rand() % 120) - 60; - } - } + for (var i = this.rows - 1; i >= 0; i--) { + for (var j = this.columns - 1; j >= 0; j--) { + this.data[i][j] = (bm.rand() % 120) - 60; + } + } } function IntegerMatrix_dotProduct(row, rowSize, otherM, columnIndex) { - var sum = 0; - for (var i = 0; i < rowSize; i++) { - sum = sum + (row[i] * otherM.data[i][columnIndex]); - } - return sum; + var sum = 0; + for (var i = 0; i < rowSize; i++) { + sum = sum + (row[i] * otherM.data[i][columnIndex]); + } + return sum; } function IntegerMatrix_multiplyBy(m) { - var rowCount = this.rows; - var columnCount = m.columns; - result = new IntegerMatrix(rowCount, columnCount); - for (var i = 0; i < rowCount; i++) { - for (var j = 0; j < columnCount; j++) { - result.data[i][j] = - this.dotProduct(this.data[i], this.columns, m, j); - } - } - return result; + var rowCount = this.rows; + var columnCount = m.columns; + var result = new IntegerMatrix(rowCount, columnCount); + for (var i = 0; i < rowCount; i++) { + for (var j = 0; j < columnCount; j++) { + result.data[i][j] = + this.dotProduct(this.data[i], this.columns, m, j); + } + } + return result; } function MMIntBenchmark() @@ -549,59 +549,59 @@ MMIntBenchmark.prototype = new AbstractBenchmark; function MMIntBenchmark_run() { - var ma, mb, mr; + var ma, mb, mr; - ma = new IntegerMatrix(10, 10); - mb = new IntegerMatrix(10, 10); - ma.fillFor(this); - mb.fillFor(this); - mr = ma.multiplyBy(mb); + ma = new IntegerMatrix(10, 10); + mb = new IntegerMatrix(10, 10); + ma.fillFor(this); + mb.fillFor(this); + mr = ma.multiplyBy(mb); } /********** MMFloatBenchmark **********/ function FloatMatrix(rowCount, columnCount) { - this.rows = rowCount; - this.columns = columnCount; - this.data = new Array(rowCount); - for (var i = rowCount - 1; i >= 0; i--) { - this.data[i] = new Array(columnCount); - } - this.fillFor = FloatMatrix_fillFor; - this.dotProduct = FloatMatrix_dotProduct; - this.multiplyBy = FloatMatrix_multiplyBy; + this.rows = rowCount; + this.columns = columnCount; + this.data = new Array(rowCount); + for (var i = rowCount - 1; i >= 0; i--) { + this.data[i] = new Array(columnCount); + } + this.fillFor = FloatMatrix_fillFor; + this.dotProduct = FloatMatrix_dotProduct; + this.multiplyBy = FloatMatrix_multiplyBy; } function FloatMatrix_fillFor(bm) { - for (var i = this.rows - 1; i >= 0; i--) { - for (var j = this.columns - 1; j >= 0; j--) { - this.data[i][j] = (1.0 * ((bm.rand() % 120) - 60)); - } - } + for (var i = this.rows - 1; i >= 0; i--) { + for (var j = this.columns - 1; j >= 0; j--) { + this.data[i][j] = (1.0 * ((bm.rand() % 120) - 60)); + } + } } function FloatMatrix_dotProduct(row, rowSize, otherM, columnIndex) { - var sum = 0; - for (var i = 0; i < rowSize; i++) { - sum = sum + (row[i] * otherM.data[i][columnIndex]); - } - return sum; + var sum = 0; + for (var i = 0; i < rowSize; i++) { + sum = sum + (row[i] * otherM.data[i][columnIndex]); + } + return sum; } function FloatMatrix_multiplyBy(m) { - var rowCount = this.rows; - var columnCount = m.columns; - result = new FloatMatrix(rowCount, columnCount); - for (var i = 0; i < rowCount; i++) { - for (var j = 0; j < columnCount; j++) { - result.data[i][j] = - this.dotProduct(this.data[i], this.columns, m, j); - } - } - return result; + var rowCount = this.rows; + var columnCount = m.columns; + var result = new FloatMatrix(rowCount, columnCount); + for (var i = 0; i < rowCount; i++) { + for (var j = 0; j < columnCount; j++) { + result.data[i][j] = + this.dotProduct(this.data[i], this.columns, m, j); + } + } + return result; } function MMFloatBenchmark() @@ -612,13 +612,13 @@ MMFloatBenchmark.prototype = new AbstractBenchmark; function MMFloatBenchmark_run() { - var ma, mb, mr; + var ma, mb, mr; - ma = new FloatMatrix(10, 10); - mb = new FloatMatrix(10, 10); - ma.fillFor(this); - mb.fillFor(this); - mr = ma.multiplyBy(mb); + ma = new FloatMatrix(10, 10); + mb = new FloatMatrix(10, 10); + ma.fillFor(this); + mb.fillFor(this); + mr = ma.multiplyBy(mb); } /********** AtAllPutBenchmark **********/ @@ -631,12 +631,12 @@ AtAllPutBenchmark.prototype = new AbstractBenchmark; function AtAllPutBenchmark_run() { - var i; - for (i = AbstractBenchmark.Vect.length - 1; i >= 0; i--) { - AbstractBenchmark.Vect[i] = 5; - } - if (AbstractBenchmark.Vect[1] != 5) - this.error("AtAllPutBenchmark"); + var i; + for (i = AbstractBenchmark.Vect.length - 1; i >= 0; i--) { + AbstractBenchmark.Vect[i] = 5; + } + if (AbstractBenchmark.Vect[1] != 5) + this.error("AtAllPutBenchmark"); } /********** StorageBenchmark **********/ @@ -651,27 +651,27 @@ StorageBenchmark.prototype = new AbstractBenchmark; function buildTreeDepth(depth) { - this.count++; - if (depth == 1) { - return new Array(Math.floor((this.rand() % 10) + 1)); - } else { - newNode = new Array(4); - newNode[0] = this.buildTreeDepth(depth - 1); - newNode[1] = this.buildTreeDepth(depth - 1); - newNode[2] = this.buildTreeDepth(depth - 1); - newNode[3] = this.buildTreeDepth(depth - 1); - return newNode; - } + this.count++; + if (depth == 1) { + return new Array(Math.floor((this.rand() % 10) + 1)); + } else { + var newNode = new Array(4); + newNode[0] = this.buildTreeDepth(depth - 1); + newNode[1] = this.buildTreeDepth(depth - 1); + newNode[2] = this.buildTreeDepth(depth - 1); + newNode[3] = this.buildTreeDepth(depth - 1); + return newNode; + } } function StorageBenchmark_run() { - this.randInit(); - this.count = 0; - this.buildTreeDepth(6); - if (this.count != 1365) { - this.error("StorageBenchmark"); - } + this.randInit(); + this.count = 0; + this.buildTreeDepth(6); + if (this.count != 1365) { + this.error("StorageBenchmark"); + } } /********** SumAllBenchmark **********/ @@ -684,16 +684,16 @@ SumAllBenchmark.prototype = new AbstractBenchmark; function SumAllBenchmark_run() { - var elementValue, sum, i; + var elementValue, sum, i; - elementValue = AbstractBenchmark.Vect[1]; - sum = 0; - for (i = AbstractBenchmark.Vect.length - 1; i >= 0; i--) { - sum = sum + AbstractBenchmark.Vect[i]; - } - if (sum != (AbstractBenchmark.Vect.length * elementValue)) { - this.error("SumAllBenchmark"); - } + elementValue = AbstractBenchmark.Vect[1]; + sum = 0; + for (i = AbstractBenchmark.Vect.length - 1; i >= 0; i--) { + sum = sum + AbstractBenchmark.Vect[i]; + } + if (sum != (AbstractBenchmark.Vect.length * elementValue)) { + this.error("SumAllBenchmark"); + } } /********** SumFromToBenchmark **********/ @@ -707,19 +707,19 @@ SumFromToBenchmark.prototype = new AbstractBenchmark; function sumFromTo(start, end) { - var sum = 0; - for (var i = start; i <= end; i++) { - sum = sum + i; - } - return sum; + var sum = 0; + for (var i = start; i <= end; i++) { + sum = sum + i; + } + return sum; } function SumFromToBenchmark_run() { - for (var i = 9; i > 0; i--) - this.sumFromTo(1, 10000); - if (this.sumFromTo(1, 10000) != 50005000) { - this.error("SumFromToBenchmark"); - } + for (var i = 9; i > 0; i--) + this.sumFromTo(1, 10000); + if (this.sumFromTo(1, 10000) != 50005000) { + this.error("SumFromToBenchmark"); + } } @@ -734,82 +734,82 @@ TakBenchmark.prototype = new AbstractBenchmark; function tak(x, y, z) { - if (y < x) { - return this.tak( - this.tak(x - 1, y, z), - this.tak(y - 1, z, x), - this.tak(z - 1, x, y)); - } else { - return z; - } + if (y < x) { + return this.tak( + this.tak(x - 1, y, z), + this.tak(y - 1, z, x), + this.tak(z - 1, x, y)); + } else { + return z; + } } function TakBenchmark_run() { - var r = this.tak(18, 12, 6); - if (r != 7) this.error("TakBenchmark"); + var r = this.tak(18, 12, 6); + if (r != 7) this.error("TakBenchmark"); } /********** TaklBenchmark **********/ function ListElement(n) { - this.val = n; - this.next = null; + this.val = n; + this.next = null; } function listn(n) { - if (n == 0) { - return null; - } else { - var newEl = new ListElement(n); - newEl.next = listn(n - 1); - return newEl; - } + if (n == 0) { + return null; + } else { + var newEl = new ListElement(n); + newEl.next = listn(n - 1); + return newEl; + } } function takl_length(l) { - if (l.next == null) { - return 1; - } else { - return 1 + takl_length(l.next); - } + if (l.next == null) { + return 1; + } else { + return 1 + takl_length(l.next); + } } function shorterp(x, y) { - var xTail, yTail; + var xTail, yTail; - xTail = x; - yTail = y; - while (yTail != null) { - if (xTail == null) return true; - xTail = xTail.next; - yTail = yTail.next; - } - return false; + xTail = x; + yTail = y; + while (yTail != null) { + if (xTail == null) return true; + xTail = xTail.next; + yTail = yTail.next; + } + return false; } function takl(x, y, z) { - if (shorterp(y, x)) { - return takl( - takl(x.next, y, z), - takl(y.next, z, x), - takl(z.next, x, y)); - } else { - return z; - } + if (shorterp(y, x)) { + return takl( + takl(x.next, y, z), + takl(y.next, z, x), + takl(z.next, x, y)); + } else { + return z; + } } function TaklBenchmark_run() { - r = takl(listn(18), listn(12), listn(6)); - if (takl_length(r) != 7) { - this.error("TaklBenchmark"); - } + var r = takl(listn(18), listn(12), listn(6)); + if (takl_length(r) != 7) { + this.error("TaklBenchmark"); + } } function TaklBenchmark() @@ -823,8 +823,8 @@ TaklBenchmark.prototype = new AbstractBenchmark; function TowersDisk(size) { - this.diskSize = size; - this.next = null; + this.diskSize = size; + this.next = null; } function TowersBenchmark() @@ -843,100 +843,100 @@ TowersBenchmark.prototype = new AbstractBenchmark; function push(d, pileIndex) { - var top = this.piles[pileIndex]; - if ((top != null) && (d.diskSize >= top.diskSize)) { - this.error("TowersBenchmark: cannot put a big disk on a smaller one"); - } - d.next = top; - this.piles[pileIndex] = d; + var top = this.piles[pileIndex]; + if ((top != null) && (d.diskSize >= top.diskSize)) { + this.error("TowersBenchmark: cannot put a big disk on a smaller one"); + } + d.next = top; + this.piles[pileIndex] = d; } function pop(pileIndex) { - var top = this.piles[pileIndex]; - if (top == null) { - this.error("TowersBenchmark: attempting to remove a disk from an empty pile"); - } - this.piles[pileIndex] = top.next; - top.next = null; - return top; + var top = this.piles[pileIndex]; + if (top == null) { + this.error("TowersBenchmark: attempting to remove a disk from an empty pile"); + } + this.piles[pileIndex] = top.next; + top.next = null; + return top; } function moveTopDisk(fromPileIndex, toPileIndex) { - this.push(this.pop(fromPileIndex), toPileIndex); - this.movesdone++; + this.push(this.pop(fromPileIndex), toPileIndex); + this.movesdone++; } function buildTowerAt(pileIndex, levels) { - for (var i = levels; i > 0; i--) { - this.push(new TowersDisk(i), pileIndex); - } + for (var i = levels; i > 0; i--) { + this.push(new TowersDisk(i), pileIndex); + } } function emptyPileAt(pileIndex) { - this.piles[pileIndex] = null; + this.piles[pileIndex] = null; } function tower(i, j, k) { - if (k == 1) { - this.moveTopDisk(i, j); - } else { - var other = (6 - i) - j; - this.tower(i, other, k - 1); - this.moveTopDisk(i, j); - this.tower(other, j, k - 1); - } + if (k == 1) { + this.moveTopDisk(i, j); + } else { + var other = (6 - i) - j; + this.tower(i, other, k - 1); + this.moveTopDisk(i, j); + this.tower(other, j, k - 1); + } } function TowersBenchmark_run() { - this.emptyPileAt(1); - this.emptyPileAt(2); - this.emptyPileAt(3); - this.buildTowerAt(1, 14); - this.movesdone = 0; - this.tower(1, 2, 14); - if (this.movesdone != 16383) this.error("TowersBenchmark"); + this.emptyPileAt(1); + this.emptyPileAt(2); + this.emptyPileAt(3); + this.buildTowerAt(1, 14); + this.movesdone = 0; + this.tower(1, 2, 14); + if (this.movesdone != 16383) this.error("TowersBenchmark"); } /********** TreeSortBenchmark **********/ function TreeNode(n) { - this.left = null; - this.right = null; - this.val = n; + this.left = null; + this.right = null; + this.val = n; this.checkTree = checkTree; this.insert = insert; } function checkTree() { - return ((this.left == null) || - ((this.left.val < this.val) && this.left.checkTree())) && - ((this.right == null) || - ((this.right.val >= this.val) && this.right.checkTree())); + return ((this.left == null) || + ((this.left.val < this.val) && this.left.checkTree())) && + ((this.right == null) || + ((this.right.val >= this.val) && this.right.checkTree())); } function insert(n) { - if (n < this.val) { - if (this.left == null) { - this.left = new TreeNode(n); - } else { - this.left.insert(n); - } - } else { - if (this.right == null) { - this.right = new TreeNode(n); - } else { - this.right.insert(n); - } - } + if (n < this.val) { + if (this.left == null) { + this.left = new TreeNode(n); + } else { + this.left.insert(n); + } + } else { + if (this.right == null) { + this.right = new TreeNode(n); + } else { + this.right.insert(n); + } + } } function TreeSortBenchmark() @@ -947,23 +947,23 @@ TreeSortBenchmark.prototype = new AbstractSortBenchmark; function TreeSortBenchmark_run() { - var vSize = 1000; + var vSize = 1000; - var v = this.randomArray(vSize); - var tree = new TreeNode(v[1]); - for (var i = 2; i <= vSize; i++) { - tree.insert(v[i]); - } - if (!tree.checkTree()) { - this.error("TreeSortBenchmark"); - } + var v = this.randomArray(vSize); + var tree = new TreeNode(v[1]); + for (var i = 2; i <= vSize; i++) { + tree.insert(v[i]); + } + if (!tree.checkTree()) { + this.error("TreeSortBenchmark"); + } } /********** BenchmarkRunner **********/ function print2col(col1, col2) { while (col1.length < 30) - col1 += " "; + col1 += " "; print(col1 + col2); } @@ -984,7 +984,7 @@ function BenchmarkRunner() print("Benchpress(v3) in JavaScript..."); print2col("benchmark", "time (ms)"); - total = total + timeit("AtAllPutBenchmark", new AtAllPutBenchmark()); + total = total + timeit("AtAllPutBenchmark", new AtAllPutBenchmark()); total += timeit("BounceBenchmark", new BounceBenchmark()); total += timeit("BubbleSortBenchmark", new BubbleSortBenchmark()); total += timeit("IncrementAllBenchmark", new IncrementAllBenchmark()); @@ -1002,12 +1002,11 @@ function BenchmarkRunner() total += timeit("SumFromToBenchmark", new SumFromToBenchmark()); total += timeit("TakBenchmark", new TakBenchmark()); total += timeit("TaklBenchmark", new TaklBenchmark()); - total += timeit("TowersBenchmark", new TowersBenchmark()); - total += timeit("TreeSortBenchmark", new TreeSortBenchmark()); + total += timeit("TowersBenchmark", new TowersBenchmark()); + total += timeit("TreeSortBenchmark", new TreeSortBenchmark()); print2col("total", total); } - BenchmarkRunner(); diff --git a/js/benchmarks/add_bench.js b/js/benchmarks/add_bench.js index 3fd477989312..804a4e0133e3 100644 --- a/js/benchmarks/add_bench.js +++ b/js/benchmarks/add_bench.js @@ -1,4 +1,5 @@ +var total=""; print("add_bench"); // add two double parameters @@ -106,7 +107,6 @@ function addDouble_V() function addDouble_VK(d1) { var t; - var d1 = 2.781828; var startTime = new Date(); for (var i = 0; i < 5000; i++) { diff --git a/js/benchmarks/array_bench.js b/js/benchmarks/array_bench.js index 83522e268537..3208523bde4f 100644 --- a/js/benchmarks/array_bench.js +++ b/js/benchmarks/array_bench.js @@ -1,4 +1,4 @@ - +var total=""; print("array_bench"); diff --git a/js/benchmarks/branch_bench.js b/js/benchmarks/branch_bench.js index 088c37d9bff4..6be0e3ed6563 100644 --- a/js/benchmarks/branch_bench.js +++ b/js/benchmarks/branch_bench.js @@ -1,3 +1,4 @@ +var total=""; print("branch_bench"); @@ -259,4 +260,4 @@ branch_P(gB, gA, "SL"); for_K(); for_V(1000000); -for_P(1000000); \ No newline at end of file +for_P(1000000); diff --git a/js/benchmarks/createObj.js b/js/benchmarks/createObj.js index 08f580135c33..c93d692f9c64 100644 --- a/js/benchmarks/createObj.js +++ b/js/benchmarks/createObj.js @@ -1,11 +1,11 @@ function f() { - var o; - for (var i=0; i < 1000; i++) { - o = new Object(); - } + var o; + for (var i=0; i < 1000; i++) { + o = new Object(); + } } var d = new Date(); f(); print("took", (new Date()) - d, "ms."); - + diff --git a/js/benchmarks/eval_bench.js b/js/benchmarks/eval_bench.js index 213ecb75eb3f..5c5a8236465b 100644 --- a/js/benchmarks/eval_bench.js +++ b/js/benchmarks/eval_bench.js @@ -1,3 +1,4 @@ +var total=""; print("eval_bench.js"); // assign to a var from within an eval @@ -36,4 +37,4 @@ function eval_1() } -eval_1(); \ No newline at end of file +eval_1(); diff --git a/js/benchmarks/func_bench.js b/js/benchmarks/func_bench.js index f43eec6235bb..21b7b1453cf2 100644 --- a/js/benchmarks/func_bench.js +++ b/js/benchmarks/func_bench.js @@ -1,4 +1,4 @@ - +var total=""; print("func_bench"); // call a function with zero parameters, returning nothing @@ -296,4 +296,4 @@ call_1B(); call_2B(); call_4B(); call_8B(); -call_4P(gP0, gP1, gP2, gP3); \ No newline at end of file +call_4P(gP0, gP1, gP2, gP3); diff --git a/js/benchmarks/getProp_bench.js b/js/benchmarks/getProp_bench.js index a43d20ea237c..7bc3d872e670 100644 --- a/js/benchmarks/getProp_bench.js +++ b/js/benchmarks/getProp_bench.js @@ -1,3 +1,4 @@ +var total; if (typeof total == "undefined") total = 0; @@ -261,6 +262,10 @@ function getProp_3() // get different properties from the this object function getProp_3a() { + //for(var list in this.prop1) + //print(list); + //return; + var t0, t1, t2, t3, t4, t5, t6, t7, t8, t9; var startTime = new Date(); @@ -395,7 +400,16 @@ getProp_2b(); var tP = { }; tP.doit = getProp_3; tP.doit2 = getProp_3a; +tP.prop0 = { }; tP.prop1 = { }; +tP.prop2 = { }; +tP.prop3 = { }; +tP.prop4 = { }; +tP.prop5 = { }; +tP.prop6 = { }; +tP.prop7 = { }; +tP.prop8 = { }; +tP.prop9 = { }; tP.doit(); tP.doit2(); @@ -436,9 +450,9 @@ deepGet_2(); // get different properties from the same object in script scope, at script scope var t0, t1, t2, t3, t4, t5, t6, t7, t8, t9; - var startTime = new Date(); + startTime = new Date(); - for (var i = 0; i < 5000; i++) { + for (i = 0; i < 5000; i++) { t0 = gP.prop0; t1 = gP.prop1; t2 = gP.prop2; t3 = gP.prop3; t4 = gP.prop4; t5 = gP.prop5; t6 = gP.prop6; t7 = gP.prop7; t8 = gP.prop8; t9 = gP.prop9; t0 = gP.prop0; t1 = gP.prop1; t2 = gP.prop2; t3 = gP.prop3; t4 = gP.prop4; t5 = gP.prop5; t6 = gP.prop6; t7 = gP.prop7; t8 = gP.prop8; t9 = gP.prop9; t0 = gP.prop0; t1 = gP.prop1; t2 = gP.prop2; t3 = gP.prop3; t4 = gP.prop4; t5 = gP.prop5; t6 = gP.prop6; t7 = gP.prop7; t8 = gP.prop8; t9 = gP.prop9; @@ -460,16 +474,16 @@ deepGet_2(); t0 = gP.prop0; t1 = gP.prop1; t2 = gP.prop2; t3 = gP.prop3; t4 = gP.prop4; t5 = gP.prop5; t6 = gP.prop6; t7 = gP.prop7; t8 = gP.prop8; t9 = gP.prop9; t0 = gP.prop0; t1 = gP.prop1; t2 = gP.prop2; t3 = gP.prop3; t4 = gP.prop4; t5 = gP.prop5; t6 = gP.prop6; t7 = gP.prop7; t8 = gP.prop8; t9 = gP.prop9; } - var elapsedTime = (new Date()).getTime() - startTime.getTime(); + elapsedTime = (new Date()).getTime() - startTime.getTime(); print("getProp_Sa : " + elapsedTime); total += elapsedTime; // get different properties from different objects in script scope, at script scope - var t0, t1, t2, t3, t4, t5, t6, t7, t8, t9; - var startTime = new Date(); + //var t1, t2, t3, t4, t5, t6, t7, t8, t9; + startTime = new Date(); - for (var i = 0; i < 5000; i++) { + for (i = 0; i < 5000; i++) { t0 = gP0.prop0; t1 = gP1.prop1; t2 = gP2.prop2; t3 = gP3.prop3; t4 = gP4.prop4; t5 = gP5.prop5; t6 = gP6.prop6; t7 = gP7.prop7; t8 = gP8.prop8; t9 = gP9.prop9; t0 = gP0.prop0; t1 = gP1.prop1; t2 = gP2.prop2; t3 = gP3.prop3; t4 = gP4.prop4; t5 = gP5.prop5; t6 = gP6.prop6; t7 = gP7.prop7; t8 = gP8.prop8; t9 = gP9.prop9; t0 = gP0.prop0; t1 = gP1.prop1; t2 = gP2.prop2; t3 = gP3.prop3; t4 = gP4.prop4; t5 = gP5.prop5; t6 = gP6.prop6; t7 = gP7.prop7; t8 = gP8.prop8; t9 = gP9.prop9; @@ -491,6 +505,6 @@ deepGet_2(); t0 = gP0.prop0; t1 = gP1.prop1; t2 = gP2.prop2; t3 = gP3.prop3; t4 = gP4.prop4; t5 = gP5.prop5; t6 = gP6.prop6; t7 = gP7.prop7; t8 = gP8.prop8; t9 = gP9.prop9; t0 = gP0.prop0; t1 = gP1.prop1; t2 = gP2.prop2; t3 = gP3.prop3; t4 = gP4.prop4; t5 = gP5.prop5; t6 = gP6.prop6; t7 = gP7.prop7; t8 = gP8.prop8; t9 = gP9.prop9; } - var elapsedTime = (new Date()).getTime() - startTime.getTime(); + elapsedTime = (new Date()).getTime() - startTime.getTime(); print("getProp_Sb : " + elapsedTime); total += elapsedTime; diff --git a/js/benchmarks/inc_bench.js b/js/benchmarks/inc_bench.js index fd8042f17293..0f9912e47c57 100644 --- a/js/benchmarks/inc_bench.js +++ b/js/benchmarks/inc_bench.js @@ -1,4 +1,4 @@ - +var total=""; print("inc_bench"); // increment a parameter diff --git a/js/benchmarks/math_bench.js b/js/benchmarks/math_bench.js index 6581184e2c1c..6ea56e158740 100644 --- a/js/benchmarks/math_bench.js +++ b/js/benchmarks/math_bench.js @@ -1,4 +1,4 @@ - +var total=""; print("math_bench"); function math_V() diff --git a/js/benchmarks/misc_bench.js b/js/benchmarks/misc_bench.js index 397b5122eb62..53be9b54759a 100644 --- a/js/benchmarks/misc_bench.js +++ b/js/benchmarks/misc_bench.js @@ -1,7 +1,7 @@ - +var total=""; print("misc_bench"); -document_1 = { }; +var document_1 = { }; document_1.live = { }; document_1.live.age = { }; document_1.live.age.value = "june 18, 1961"; @@ -9,30 +9,30 @@ document_1.live.time1 = { }; document_1.live.time2 = { }; document_1.live.time3 = { }; -window = { }; +var window = { }; function setTimeout() { } function lifetimer(){ - today = new Date() - BirthDay = new Date(document_1.live.age.value) + var today = new Date() + var BirthDay = new Date(document_1.live.age.value) + var timeold = (today.getTime() - BirthDay.getTime()); + var sectimeold = timeold / 1000; + var secondsold = Math.floor(sectimeold); + var msPerDay = 24 * 60 * 60 * 1000 ; timeold = (today.getTime() - BirthDay.getTime()); - sectimeold = timeold / 1000; - secondsold = Math.floor(sectimeold); - msPerDay = 24 * 60 * 60 * 1000 ; - timeold = (today.getTime() - BirthDay.getTime()); - e_daysold = timeold / msPerDay; - daysold = Math.floor(e_daysold); - e_hrsold = (e_daysold - daysold)*24; - hrsold = Math.floor(e_hrsold); - minsold = Math.floor((e_hrsold - hrsold)*60); + var e_daysold = timeold / msPerDay; + var daysold = Math.floor(e_daysold); + var e_hrsold = (e_daysold - daysold)*24; + var hrsold = Math.floor(e_hrsold); + var minsold = Math.floor((e_hrsold - hrsold)*60); document_1.live.time1.value = daysold document_1.live.time2.value = hrsold document_1.live.time3.value = minsold window.status = "Well at the moment you are " + secondsold + "............ seconds old."; - timerID = setTimeout("lifetimer()",1000) + var timerID = setTimeout("lifetimer()",1000) } function misc_1() @@ -40,7 +40,7 @@ function misc_1() var startTime = new Date(); for (var i = 0; i < 5000; i++) lifetimer(); - elapsedTime = (new Date()).getTime() - startTime.getTime(); + var elapsedTime = (new Date()).getTime() - startTime.getTime(); print("misc_1 : ", elapsedTime); total += elapsedTime; } @@ -54,7 +54,7 @@ function MakeArray(n) { } //Initialize Days of Week Array -days = new MakeArray(7); +var days = new MakeArray(7); days[0] = "Saturday" days[1] = "Sunday" days[2] = "Monday" @@ -64,7 +64,7 @@ days[5] = "Thursday" days[6] = "Friday" //Initialize Months Array -months = new MakeArray(12); +var months = new MakeArray(12); months[1] = "January" months[2] = "February" months[3] = "March" @@ -78,7 +78,7 @@ months[10] = "October" months[11] = "November" months[12] = "December" -form = { }; +var form = { }; form.day = { }; form.day.value = "14"; form.month = { }; @@ -128,7 +128,7 @@ function misc_2() for (var i = 0; i < 5000; i++) { compute(form); compute(form); } - elapsedTime = (new Date()).getTime() - startTime.getTime(); + var elapsedTime = (new Date()).getTime() - startTime.getTime(); print("misc_2 : ", elapsedTime); total += elapsedTime; } @@ -138,7 +138,7 @@ function misc_2() // http://www.geocities.com/SiliconValley/Heights/2052 // Copyright 1996 Chris Englmeier -Input = { }; +var Input = { }; Input.value = 4096; function Newton(Input){ @@ -160,7 +160,7 @@ function misc_3() for (var i = 0; i < 5000; i++) { Newton(Input); Newton(Input); Newton(Input); Newton(Input); Newton(Input); Newton(Input); } - elapsedTime = (new Date()).getTime() - startTime.getTime(); + var elapsedTime = (new Date()).getTime() - startTime.getTime(); print("misc_3 : ", elapsedTime); total += elapsedTime; } @@ -181,8 +181,8 @@ var al=" abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" var ns="0123456789"; function iA(){ - this.length=iA.arguments.length; - for (var i=0;i