
Ask HN: What's the Running Time of Node's Array.push and Array.unshift? - adriansky
I don&#x27;t know C&#x2F;C++ very well, but I&#x27;m trying to figure out where `Array.push` is implemented on the Node source code.<p>Is this one https:&#x2F;&#x2F;github.com&#x2F;v8&#x2F;v8&#x2F;blob&#x2F;master&#x2F;src&#x2F;builtins&#x2F;builtins-array.cc#L145?<p>Ultimately, what I want to know if the runtime of the Array.push and Array.unshift implementation.<p>Based on the ECMA2019, It seems like push is O(1)
https:&#x2F;&#x2F;tc39.github.io&#x2F;ecma262&#x2F;#sec-array.prototype.push<p>and unshift is O(n)?
https:&#x2F;&#x2F;tc39.github.io&#x2F;ecma262&#x2F;#sec-array.prototype.unshift
======
skate22
I asked this to about 5 devs around 4 months ago and no one knew. I was
surprised how hard it is to find the complexity for standard js functions

------
sergiaguilar
don't know

~~~
sergiaguilar
true

~~~
sergiaguilar
yes

