Here's a benchmark where the comment after each option shows the median time of a thousand runs in ms:
let opt=[
'Array(n).fill().map((_,i)=>i)', // 2.71
'Array(n).fill().map(function(_,i){return i})', // 2.73
'let o=[];for(let i=0;i<1e5;i++)o[i]=i', // 3.29
'let o=[];for(let i=0;i<1e5;i++)o.push(i)', // 3.31
'let o=[];for(let i=0,n2=n;i<n2;i++)o[i]=i', // 3.38
'let o=[];for(let i=0;i<n;i++)o[i]=i', // 3.57
'Array.apply(null,Array(n)).map(Function.prototype.call.bind(Number))', // 3.64
'Array.apply(0,Array(n)).map((_,i)=>i)', // 3.73
'Array.apply(null,Array(n)).map((_,i)=>i)', // 3.77
'o2=[];for(let i=0;i<n;i++)o2[i]=i', // 4.42
'[...Array(n).keys]', // 7.07
'Array.from({length:n},(_,i)=>i)', // 7.13
'Array.from(Array(n),(_,i)=>i)', // 7.23
'o3=[];for(i3=0;i3<n;i3++)o3[i3]=i3' // 24.34
]
let n=1e5
opt.sort(()=>Math.random()-.5)
for(let opti of opt){
let t1=process.hrtime.bigint()
eval(opti)
let t2=process.hrtime.bigint()
console.log(t2-t1+'\t'+opti)
}
The for loop became a lot faster when I used block-scoped variables instead of global variables.
I used median time instead of mean because occasionally a single run can take much longer than typical runs which distorts the mean time.
I ran the benchmark like for i in {1..1000};do node seqbench.js;done, because when I invoked the script only once but I ran each option 1000 times inside the script, it was affected by some kind of an optimization where the for loops became the fastest options.