Skip to content

Instantly share code, notes, and snippets.

@mraleph
Created July 23, 2014 21:29
Show Gist options
  • Save mraleph/99579ede7c52d1018f2d to your computer and use it in GitHub Desktop.
Save mraleph/99579ede7c52d1018f2d to your computer and use it in GitHub Desktop.
function B1() {
/* Benchmark.prototype.setup goes here {{{ */
var arr1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
seed_data = 3,
result = 0;
/* }}} */
var start = new Date;
while (...) { /* do N iterations of test body */
/* body of the case goes here {{{ */
for (var i = 0; i < arr1.length; i++) {
result += (seed_data * i);
}
/* }}} */
}
var end = new Date;
/* N / (end - start) gives ops per ms result */
}
function B2() {
/* Benchmark.prototype.setup goes here {{{ */
var arr1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
seed_data = 3,
result = 0;
/* }}} */
var start = new Date;
while (...) { /* do N iterations of test body */
/* body of the case goes here {{{ */
var l = arr1.length;
for (var i = 0; i < l; i++) {
result += (seed_data * i);
}
/* }}} */
}
var end = new Date;
/* N / (end - start) gives ops per ms result */
}
function B3() {
/* Benchmark.prototype.setup goes here {{{ */
var arr1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
seed_data = 3,
result = 0;
/* }}} */
var start = new Date;
while (...) { /* do N iterations of test body */
/* body of the case goes here {{{ */
var arr2 = [1, 2, 3, 4, 5, 6, 7, 8, 9];
for (var i = 0; i < arr2.length; i++) {
result += (seed_data * i);
if (i === 4) {
arr2.push(10)
}
}
/* }}} */
}
var end = new Date;
/* N / (end - start) gives ops per ms result */
}
@fcsonline
Copy link

Awesome! Thanks for help me to find the right case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment