Adding Time Complexity Annotation Where Applicable #520
-
It would be cool if the MDN docs included performance and efficiency data within the documentation. Just an idea, what do you all think? |
Beta Was this translation helpful? Give feedback.
Replies: 0 comments 7 replies
-
The ECMAScript specification does give algorithms that engines should follow, and we can analyse their Big-O notation complexities, but engines are only required to act "as if" following such algorithms, therefore are open to implementations that, for example, completely elude memory usage for a particular algorithm, or possibly (although unlikely) perform more internal work therefore this doesn't seem possible to accurately describe what performance characteristics can be expected. Take Another example is from the the specification for
|
Beta Was this translation helpful? Give feedback.
-
@phosra I see your point and it is very valid. The ECMA standard is explicit but the time/space complexity is too dependent on the particular JS engine. Great response, thanks! |
Beta Was this translation helpful? Give feedback.
The ECMAScript specification does give algorithms that engines should follow, and we can analyse their Big-O notation complexities, but engines are only required to act "as if" following such algorithms, therefore are open to implementations that, for example, completely elude memory usage for a particular algorithm, or possibly (although unlikely) perform more internal work therefore this doesn't seem possible to accurately describe what performance characteristics can be expected.
Take
Array#unshift
: this could be amortized to anO(log(n))
operation in engine implementations that keep a base pointer in their array data structure and allocate memory on both ends when deemed necessary, ye…