package de.ids_mannheim.korap.benchmark;

import java.util.*;
import java.io.*;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import de.ids_mannheim.korap.KrillIndex;
import de.ids_mannheim.korap.KrillQuery;
import de.ids_mannheim.korap.KrillCollection;
import de.ids_mannheim.korap.query.QueryBuilder;
import de.ids_mannheim.korap.Krill;
import de.ids_mannheim.korap.response.Result;
import de.ids_mannheim.korap.util.QueryException;

import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.Ignore;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;


@RunWith(JUnit4.class)
public class TestBenchmarkSamples {

    private final ObjectMapper mapper = new ObjectMapper();
    private final int rounds = 1000;
    private long t1 = 0, t2 = 0;


    @Test
    public void simpleSegmentQuery () throws Exception {
        // Construct index

        KrillIndex ki = new KrillIndex();

        // Indexing test files
        for (String i : new String[] { "00001", "00002", "00003", "00004",
                "00005", "00006", "02439" }) {
            ki.addDoc(getClass().getResourceAsStream("/wiki/" + i + ".json.gz"),
                    true);
        };
        ki.commit();

        t1 = System.nanoTime();
        for (int i = 1; i <= rounds; i++) {
            final QueryBuilder qb = new QueryBuilder("tokens");
            final Krill ks = new Krill(qb.seg("mate/m:gender:masc").toQuery());
            final Result kr = ks.apply(ki);
            assertEquals(kr.getTotalResults(), 497);
        };
        t2 = System.nanoTime();
        double seconds = (double) (t2 - t1) / 1000000000.0;
        System.err.println("Seconds: " + seconds);

        // Seconds: 9.465514311
        // Seconds: 9.302011468
        // Seconds: 9.052496918
        // Seconds: 9.0567007
        // Seconds: 9.113724089
        // Seconds: 8.700548842
        // Seconds: 9.390980437
        // Seconds: 8.817503952
    };
};

@@ -303,16 +303,56 @@
 ection;%0A
+import de.ids_mannheim.korap.KrillMeta;%0A
 import d
@@ -392,16 +392,16 @@
 uilder;%0A
-
 import d
@@ -1003,16 +1003,40 @@
 Index();
+%0A        double seconds;
 %0A%0A      
@@ -1687,31 +1687,24 @@
 ();%0A        
-double 
 seconds = (d
@@ -1755,11 +1755,11 @@
 tem.
-err
+out
 .pri
@@ -2010,16 +2010,16 @@
 0980437%0A
-
         
@@ -2042,16 +2042,728 @@
 7503952%0A
+        // New machine (ND):%0A        // Seconds: 3.679194927%0A        // EM%0A        // Seconds: 3.176065455%0A        // No snippets - Seconds: 1.620091942%0A%0A        t1 = System.nanoTime();%0A        for (int i = 1; i %3C= rounds; i++) %7B%0A            final QueryBuilder qb = new QueryBuilder(%22tokens%22);%0A            final Krill ks = new Krill(qb.seg(%22mate/m:gender:masc%22).toQuery());%0A            KrillMeta meta = ks.getMeta();%0A            meta.setSnippets(false);%0A            final Result kr = ks.apply(ki);%0A            assertEquals(kr.getTotalResults(), 497);%0A        %7D;%0A        t2 = System.nanoTime();%0A        seconds = (double) (t2 - t1) / 1000000000.0;%0A        System.out.println(%22No snippets - Seconds: %22 + seconds);%0A
     %7D;%0A%7D

Improve Benchmarking to check no-snippets retrieval