package ca.junctionbox.cljbuck.lexer.benchmarks;

import ca.junctionbox.cljbuck.lexer.Item;
import ca.junctionbox.cljbuck.lexer.Lexable;
import org.jcsp.lang.CSProcess;
import org.jcsp.lang.Channel;
import org.jcsp.lang.ChannelInput;
import org.jcsp.lang.One2OneChannel;
import org.jcsp.lang.Parallel;
import org.jcsp.util.Buffer;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

import java.util.LinkedList;
import java.util.Queue;

public class LexerBenchmark {

    @Benchmark
    public void BenchmarkLexer() {
        final One2OneChannel<Object> chan = Channel.one2one(new Buffer(2048));
        final Lexable l = Lexable.create("comment.clj",
                "(ns my.core (:require [hello.world.extended :as ext])\n\n\n(defn hello [name]\n (prn \"Hola \" name))", chan.out());

        ConsumeTask task = new ConsumeTask(chan.in());

        new Parallel(new CSProcess[]{
                (CSProcess) l,
                task,
        }).run();
    }

    public static void main(String[] args) throws RunnerException {
        Options opt = new OptionsBuilder()
                .include(LexerBenchmark.class.getSimpleName())
                .forks(1)
                .build();

        new Runner(opt).run();
    }
}

class ConsumeTask implements CSProcess {
    final Queue<Item> items = new LinkedList<>();
    private final ChannelInput<Object> in;

    ConsumeTask(ChannelInput<Object> in) {
        this.in = in;
    }

    @Override
    public void run() {
        for (;;) {
            final Item item = (Item) in.read();
            if (item == null) {
                break;
            }
            items.add(item);
        }
    }
}
@@ -134,202 +134,8 @@
 le;%0A
-import org.jcsp.lang.CSProcess;%0Aimport org.jcsp.lang.Channel;%0Aimport org.jcsp.lang.ChannelInput;%0Aimport org.jcsp.lang.One2OneChannel;%0Aimport org.jcsp.lang.Parallel;%0Aimport org.jcsp.util.Buffer;%0A
 impo
@@ -447,16 +447,22 @@
 hmark %7B%0A
+    /*
 %0A    @Be
@@ -1214,434 +1214,13 @@
   %7D%0A
-%7D%0A%0Aclass ConsumeTask implements CSProcess %7B%0A    final Queue%3CItem%3E items = new LinkedList%3C%3E();%0A    private final ChannelInput%3CObject%3E in;%0A%0A    ConsumeTask(ChannelInput%3CObject%3E in) %7B%0A        this.in = in;%0A    %7D%0A%0A    @Override%0A    public void run() %7B%0A        for (;;) %7B%0A            final Item item = (Item) in.read();%0A            if (item == null) %7B%0A                break;%0A            %7D%0A            items.add(item);%0A        %7D%0A    %7D%0A%7D
+    */%0A%7D%0A

Remove JCSP cruft from Benchmark.