Search code examples
javastringcomplexity-theoryjavadocreplaceall

Why doesn't Java include the time/space complexity of each function in the javadoc?


Hi I want to know what is the time complexity of the "replaceAll" function of the String class but I can't find any information on it.(http://docs.oracle.com/javase/6/docs/api/java/lang/String.html)

Wouldn't it be better for Java to include the complexities in the Javadoc? I believe it's a very important thing for someone to know.


Solution

  • Most functions have fairly straight forward time complexities. AFAIK, replaceAll is O(n)

    IMHO. Nothing beats testing this yourself empirically e.g. with a profiler, because its highly likely that 99% of the methods you use have little to no impact on the performance of your application.