Splicing a single value (v35)

Revision 35 of this benchmark created on


Setup

var arr = [];
    for (var i = 0; i < 100; i++) {
     arr.push(i);
    };
    var half = Math.floor(arr.length / 2);
      
    function randomInt(max) {
     return Math.floor(Math.random() * (max + 1));
    };

Test runner

Ready to run.

Testing in
TestOps/sec
Loop and splice
for (var i = 0; i < arr.length; i++) {
  for (var j = 0; j < arr.length; j++) {
    if (Math.floor(arr.length / 2) == j) {
      arr.splice(j, 1);
      break;
    }
  }
}
ready
Loop no splice
for (var i = 0; i < arr.length; i++) {
  for (var j = 0; j < arr.length; j++) {
    if (Math.floor(arr.length / 2) == j) {
      break;
    }
  }
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.