Push item inside an array (v4)

Revision 4 of this benchmark created by JLA on


Description

Test different ways to add items to the end of an array

Setup

var arr = [1, 2, 3, 4, 5, 6, 7];
    
    function fn_push() {
      arr.push(8);
    }
    
    function fn_push_manually() {
      arr[arr.length] = 8;
    }
    
    function fn_concat_end() {
      arr.concat([8])
    }
    
    function fn_push_array() {
      arr.push.apply(arr, [8]);
    }

Teardown


    var arr = [1, 2, 3, 4, 5, 6, 7];
  

Test runner

Ready to run.

Testing in
TestOps/sec
Add element at the end of Array with push()
fn_push()
ready
Add element at the end of Array using the length property
fn_push_manually()
ready
Add element at the end of Array with concat()
fn_concat_end()
ready
Add element at the end of Array with arr.push.apply
fn_push_array()
ready

Revisions

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