Hi Ralph, I see one issue in your benchmark:
StackWalker walker = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE);
will return a new StackWalker every time it's called. I'd suggest to create the StackWalker only once and put it in a private (or package) static. This will eliminate the creation cost of StackWalker from the benchmark. On 13/03/2017 18:52, Ralph Goers wrote:
The “search” that uses StackWalker probably walks it to the end because I had to use test() to determine the StackFrame to return. If you can provide a better algorithm to use I’d be happy to retest it. If I=0 is the current StackFrame, then that is what we do. Please take a look at the stackwalkerSearch method at https://github.com/rgoers/stackwalker-vs-Reflection_getCallerClass/blob/master/java9/src/main/java/org/github/arnaudroger/StackWalkerGetCallerClass.java.
I'm curious as to why using reduce() as opposed to findFirst(). Won't reduce() continue to walk the stack even when the searched frame is found? best regards, -- daniel
