package org.spoofax.jsglr2.benchmark.jsglr2;

import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.infra.Blackhole;
import org.spoofax.jsglr2.JSGLR2Variant;
import org.spoofax.jsglr2.benchmark.BenchmarkTestSetReader;
import org.spoofax.jsglr2.integration.IntegrationVariant;
import org.spoofax.jsglr2.integration.ParseTableVariant;
import org.spoofax.jsglr2.parser.ParseException;
import org.spoofax.jsglr2.testset.TestSet;
import org.spoofax.jsglr2.testset.testinput.StringInput;

public class JSGLR2BenchmarkParsingExternal extends JSGLR2Benchmark<String, StringInput> {

    public JSGLR2BenchmarkParsingExternal() {
        String[] args = System.getProperty("language").split(" ");

        TestSet<String, StringInput> testSet = TestSet.fromArgs(args);

        this.testSetReader = new BenchmarkTestSetReader<>(testSet);
    }

    @Param({ "standard", "elkhound", "recovery", "recoveryElkhound", "incremental",
        "recoveryIncremental" }) JSGLR2Variant.Preset jsglr2Variant;

    @Override protected IntegrationVariant variant() {
        return new IntegrationVariant(new ParseTableVariant(), jsglr2Variant.variant);
    }

    @Override protected boolean implode() {
        return false;
    }

    @Override protected Object action(Blackhole bh, StringInput input) throws ParseException {
        return jsglr2.parser.parseUnsafe(input.content, input.filename, null);
    }

}

@@ -74,21 +74,105 @@
 tations.
-Param
+Level;%0Aimport org.openjdk.jmh.annotations.Param;%0Aimport org.openjdk.jmh.annotations.Setup
 ;%0Aimport
@@ -306,16 +306,145 @@
 Reader;%0A
+import org.spoofax.jsglr2.imploder.incremental.IncrementalTreeImploder;%0Aimport org.spoofax.jsglr2.incremental.IncrementalParser;%0A
 import o
@@ -1421,32 +1421,359 @@
 n false;%0A    %7D%0A%0A
+    @Setup(Level.Invocation) public void clearCache() %7B%0A        if(parser instanceof IncrementalParser) %7B%0A            ((IncrementalParser) jsglr2.parser).clearCache();%0A%0A            if(jsglr2.imploder instanceof IncrementalTreeImploder)%0A                ((IncrementalTreeImploder) jsglr2.imploder).clearCache();%0A        %7D%0A    %7D%0A%0A
     @Override pr

Clear cache of incremental parser per invocation