I’m interested to know if there already exists an approach that takes java method code as an input and determines the cost function of such code (number of loops, ifs/elses, I/Os and other common things).
I mean not the exact cost in ms but some general cost that this code may cause.
The thing is that I want to be able for the arbitrary method that user writes to say what can be the the cost of such method (of course not taking into accounts some specificities like the JVM etc.).
I’m interested to know if there already exists an approach that takes java method
Share
I do not know if such a tool exists, but I doubt both its feasibility and its usability:
For the feasibility of such a tool in the general case have a look at the Halting problem, which is a significant part of what you are asking for and has been proven to be undecidable.
For the usability of such a tool, I believe that static code analysis on its own is useless, because a significant part of the performance of a system depends on its usage patterns, i.e. on its input.
There is a reason that even benchmarking systems at runtime is not straight-forward; the same software could be amazingly fast in some cases and staggeringly slow in others.
That said, there are several tools for code complexity analysis, but those metrics focus on structural complexity, which relates more to quality and maintainability than performance.