Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Temp Test
(version: 12)
Comparing performance of:
push vs arr.length++; vs arr[j++]
Created:
5 months ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
const num2code = (n)=> n < 10 ? 0x30 + n : n < 36 ? 0x61 + (n - 10) : 0x41 + (n - 36); const getInt = (()=>{r=Math.random;f=Math.floor;return (a=0,b=0x100000000)=>f(r()*(b-a))+a})(); const getStr = (n)=>String.fromCharCode(...(new Int32Array(n)).map(()=>num2code(getInt(0,62)))); const N = 0x10000;
Tests:
push
const arr = []; for(i=0; i<N; i++) arr.push(getInt());
arr.length++;
const arr = []; for(i=0; i<N; i++) arr[arr.length] = getInt();
arr[j++]
const arr = []; let j = 0; for(i=0; i<N; i++) arr[j++] = getInt();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
push
arr.length++;
arr[j++]
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
5 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36
Browser/OS:
Chrome 142 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
push
347.9 Ops/sec
arr.length++;
504.6 Ops/sec
arr[j++]
507.9 Ops/sec
Related benchmarks:
String.split: Random vs Fixed strings
IntersectionwithLodashVsCustomObjectBased
ASKDFJLASKDFJLASKJDLASKDJFLASKDaS
array pre alloc n
fast floor vs floor js
fast floor vs floor js vs unsafe floor
Array timing 100
getMiddle: Math.floor vs num % 2
Unique Instance Test
Comments
Confirm delete:
Do you really want to delete benchmark?