package skadistats.clarity.examples.test;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import skadistats.clarity.processor.entities.UsesEntities;
import skadistats.clarity.processor.runner.ControllableRunner;
import skadistats.clarity.source.MappedFileSource;

import java.util.Random;

@UsesEntities
public class Main {

    private final Logger log = LoggerFactory.getLogger(Main.class.getPackage().getClass());

    public void run(String[] args) throws Exception {
        ControllableRunner runner = new ControllableRunner(new MappedFileSource(args[0])).runWith(this);
        while(!runner.isAtEnd()) {
            long tStart = System.nanoTime();
            runner.tick();
            long tTick = System.nanoTime() - tStart;
            log.info("tick {} took {} microseconds", runner.getTick(), tTick / 1000.0f);
        }
        runner.halt();
    }

    public void runSeek(String[] args) throws Exception {
        ControllableRunner runner = new ControllableRunner(new MappedFileSource(args[0])).runWith(this);
        int lastTick = runner.getLastTick();
        Random r = new Random();
        int i = 100;
        while (i > 0) {
            long tStart = System.nanoTime();
            runner.seek(r.nextInt(lastTick));
            long tTick = System.nanoTime() - tStart;
            log.info("seek to {} took {} microseconds", runner.getTick(), tTick / 1000.0f);
            i--;
        }
        runner.halt();
    }


    public static void main(String[] args) throws Exception {
        new Main().runSeek(args);
    }

}

@@ -133,29 +133,27 @@
 sor.
-entities.UsesEntities
+runner.SimpleRunner
 ;%0Aim
@@ -190,33 +190,36 @@
 sor.
-runner.ControllableRunner
+stringtables.UsesStringTable
 ;%0Aim
@@ -272,47 +272,44 @@
 e;%0A%0A
-import java.util.Random;%0A%0A@UsesEntities
+@UsesStringTable(%22instancebaseline%22)
 %0Apub
@@ -485,684 +485,121 @@
     
-ControllableRunner runner = new ControllableRunner(new MappedFileSource(args%5B0%5D)).runWith(this);%0A        while(!runner.isAtEnd()) %7B%0A            long tStart = System.nanoTime();%0A            runner.tick();%0A            long tTick = System.nanoTime() - tStart;%0A            log.info(%22tick %7B%7D took %7B%7D microseconds%22, runner.getTick(), tTick / 1000.0f);%0A        %7D%0A        runner.halt();%0A    %7D%0A%0A    public void runSeek(String%5B%5D args) throws Exception %7B%0A        ControllableRunner runner = new ControllableRunner(new MappedFileSource(args%5B0%5D)).runWith(this);%0A        int lastTick = runner.getLastTick();%0A        Random r = new Random();%0A        int i = 100;%0A        while (i %3E 0) %7B%0A    
+long tStart = System.currentTimeMillis();%0A        new SimpleRunner(new MappedFileSource(args%5B0%5D)).runWith(this);%0A
     
@@ -600,37 +600,37 @@
 ;%0A        long t
-Start
+Match
  = System.nanoTi
@@ -627,106 +627,25 @@
 tem.
-nanoTime();%0A            runner.seek(r.nextInt(lastTick));%0A            long tTick = System.nanoTime
+currentTimeMillis
 () -
@@ -661,20 +661,16 @@
         
-  
-  
 log.info
@@ -675,125 +675,49 @@
 fo(%22
-seek to %7B%7D took %7B%7D microseconds%22, runner.getTick(), tTick / 1000.0f);%0A            i--;%0A        %7D%0A        runner.halt(
+total time taken: %7B%7Ds%22, (tMatch) / 1000.0
 );%0A 
@@ -722,17 +722,16 @@
 %0A    %7D%0A%0A
-%0A
     publ
@@ -776,32 +776,32 @@
 ows Exception %7B%0A
+
         new Main
@@ -810,12 +810,8 @@
 .run
-Seek
 (arg

refactor string table decoding, to not generate a lot of intermediate objects