/*
 * @author Ranides Atterwim {@literal <ranides@gmail.com>}
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira
 */
package net.ranides.assira.trace;

import net.ranides.benchmark.app.BenchmarkName;
import net.ranides.benchmark.app.BenchmarkRunner;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.runner.RunnerException;

import java.io.IOException;

/**
 * Benchmark for JDK11 StackWalker
 *
 */
public class Walker11Benchmark {

    private static final FStackWalker11 walker = new FStackWalker11();

    @Benchmark
    @BenchmarkName("frameNative")
    public int frameNative() {
        return walker.getFrame(1).getLineNumber();
    }


    @Benchmark
    @BenchmarkName("frameListNative")
    public int frameListNative() {
        int ret = 0;
        for(StackTraceElement e : walker.getFrames()) {
            ret += e.getLineNumber();
        }
        return ret;
    }


    @Benchmark
    @BenchmarkName("list")
    public int list() {
        return walker.getTypes().size();
    }

    @Benchmark
    @BenchmarkName("callee")
    public int callee() {
        return walker.getType(0).getName().length();
    }

    @Benchmark
    @BenchmarkName("caller")
    public int caller() {
        return walker.getType(1).getName().length();
    }

    public static void main(String[] args) throws RunnerException, IOException {
        BenchmarkRunner.run(Walker11Benchmark.class);
    }
    
}
