merge-array implementations

JavaScript performance comparison

Revision 60 of this test case created by Sultan

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var arr1 = Array.from(Array(1000), (x,i) => ((i + 1) + ''))
  var arr2 = Array.from(Array(10), (x,i) => ((i - 1) + ''))
  
  var arr1Length = arr1.length; 
  var arr2Length = arr2.length; 

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
push (naive 3)
arr1.push(null)
pending…
concat (naive 2)
// Create result array with preallocated size
var arr3 = Array(arr1Length + 1)

// Add Array 1
for(var i = 0; i < arr1Length; i++){
  arr3[i] = arr1[i]
}

arr3[arr1Length] = null
pending…
slice(0)
// Create result array with preallocated size
var arr3 = arr1.slice(0)

arr3[arr1Length] = null
pending…
push (naive 2)
// Pre allocate size
arr1.length = arr1Length + 1

// Add arr2 items to arr1
arr1[arr1Length] = null
pending…
push (naive 1)
arr1[arr1Length] = null
pending…
slice()
// Create result array with preallocated size
var arr3 = arr1.slice()

arr3[arr1Length] = null
pending…
concat (naive 1)
// Create result array
var arr3 = []

// Add Array 1
for(var i = 0; i < arr1Length; i++){
  arr3[i] = arr1[i]
}

arr3[arr1Length] = null
pending…
concat
arr1 = arr1.concat(null)
pending…

Revisions

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

0 Comments