New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Perfomance penalty of java.util.Stack
#28
Comments
Nice! |
No problem, I've been using |
Cherry picked this into master. |
@dktcoding |
@fasseg yes, the information is accurate. Thanks! |
I've been profiling
exp4j
in particularExpression.evaluate()
, from the profiling I gathered the following data (using Netbeans profiler):The results show that most of the time used by
Expression.evaluate()
is wasted on the use ofjava.util.Stack
which is backed byjava.util.Vector
.I tested again using
java.util.LinkedList
which can be used as a drop in replacement forjava.util.stack
, it shows some improvements (~15%) but the boxing/unboxing process still takes up a lot of time.Finally I've created a simple
ArrayStack
class that works with an array of doubles directly and doesn't need to box/unbox nor to adapt the methods fromjava.util.Vector
topush()
andpop()
. The final result is that theExpression.evaluate()
uses less than 50% of the time.About the table:
The second column of the table is the total time in ms used by the method in 1M excecutions.
The profiled code was:
Looking forward now most of the time seems to be used retrieving the variable values.
The text was updated successfully, but these errors were encountered: