I found some info regarding time complexity of certain JavaScript functions like push
, pop
, shift
, slice
or splice
, but was wondering what the time complexity of parseInt()
(or, as a bonus, parseFloat()
)
Asked
Active
Viewed 3,375 times
1

Community
- 1
- 1

Patrick E.
- 165
- 1
- 2
- 9
-
2You would be hard-pressed to make it anything but O(N), with N being the length of the input string. – Oleg Estekhin Nov 05 '16 at 08:27
-
Just wondering why you are curious about this. In such cases normally constants and multipliers dominate the actual time taken, whether it's O(1) or O(n) or O(n2) or O(n!) or anything else. – Nov 05 '16 at 08:41
1 Answers
3
This is not stated explicitly in the specification, buy you may assume that it is linear by the number of characters representing the value being parsed.

kgeorgiy
- 1,477
- 7
- 9
-
2Why would anyone expect it to be stated in the specification? If's a function of the implementation. – Nov 05 '16 at 08:41
-
@torazaburo 1) Thank you for editing. 2) To limit possible implementations. For example, the exponential-time algorithm conforms current specification. – kgeorgiy Nov 05 '16 at 08:45
-
Minor point, but I'm not aware of any feature in the spec which is constrained in terms of O(). – Nov 05 '16 at 08:57
-
There are, but very few, e.g. [Section 23.1](http://www.ecma-international.org/ecma-262/6.0/#sec-map-objects) states: Map object must be implemented using either hash tables or other mechanisms that, on average, provide access times that are **sublinear** on the number of elements in the collection. – kgeorgiy Nov 05 '16 at 09:00