Ask HN: What's the Running Time of Node's Array.push and Array.unshift?

1 points by adriansky ↗ HN
I don't know C/C++ very well, but I'm trying to figure out where `Array.push` is implemented on the Node source code.

Is this one https://github.com/v8/v8/blob/master/src/builtins/builtins-array.cc#L145?

Ultimately, what I want to know if the runtime of the Array.push and Array.unshift implementation.

Based on the ECMA2019, It seems like push is O(1) https://tc39.github.io/ecma262/#sec-array.prototype.push

and unshift is O(n)? https://tc39.github.io/ecma262/#sec-array.prototype.unshift

4 comments

[ 5.1 ms ] story [ 20.9 ms ] thread
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