Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array.push
(version: 8)
Comparing performance of:
direct addition vs Array.push without comma vs Array.push with comma
Created:
9 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var n = 10; function Person(name, age) { this.name = name; this.age = age; }
Tests:
direct addition
var arr = [ new Person(1 + '', 24), new Person(2 + '', 24), new Person(3 + '', 24), new Person(4 + '', 24), new Person(5 + '', 24), new Person(6 + '', 24), new Person(7 + '', 24), new Person(8 + '', 24), new Person(9 + '', 24), new Person(10 + '', 24) ].join(',');
Array.push without comma
var arr = []; arr.push (new Person(1 + '', 24)); arr.push (new Person(2 + '', 24)); arr.push (new Person(3 + '', 24)); arr.push (new Person(4 + '', 24)); arr.push (new Person(5 + '', 24)); arr.push (new Person(6 + '', 24)); arr.push (new Person(7 + '', 24)); arr.push (new Person(8 + '', 24)); arr.push (new Person(9 + '', 24)); arr.push (new Person(10 + '', 24)); arr.join(',');
Array.push with comma
var arr = []; arr.push ( new Person(1 + '', 24), new Person(2 + '', 24), new Person(3 + '', 24), new Person(4 + '', 24), new Person(5 + '', 24),new Person(6 + '', 24),new Person(7 + '', 24), new Person(8 + '', 24),new Person(9 + '', 24),new Person(10 + '', 24) ); arr.join(',');
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
direct addition
Array.push without comma
Array.push with comma
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
push vs spread for single element addition to array
array spread vs array push
Spread or Push
Add new element to array: push vs push with i
test map lodash vs array
Comments
Confirm delete:
Do you really want to delete benchmark?