| Akron | 98b7854 | 2015-08-06 21:43:08 +0200 | [diff] [blame] | 1 | package de.ids_mannheim.korap.benchmark; |
| 2 | |
| 3 | import java.util.*; |
| 4 | import java.io.*; |
| 5 | |
| 6 | import com.fasterxml.jackson.databind.JsonNode; |
| 7 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 8 | |
| 9 | import de.ids_mannheim.korap.KrillIndex; |
| 10 | import de.ids_mannheim.korap.KrillQuery; |
| 11 | import de.ids_mannheim.korap.KrillCollection; |
| 12 | import de.ids_mannheim.korap.query.QueryBuilder; |
| 13 | import de.ids_mannheim.korap.Krill; |
| 14 | import de.ids_mannheim.korap.response.Result; |
| 15 | import de.ids_mannheim.korap.util.QueryException; |
| 16 | |
| 17 | import static org.junit.Assert.*; |
| 18 | import org.junit.Test; |
| 19 | import org.junit.Ignore; |
| 20 | import org.junit.runner.RunWith; |
| 21 | import org.junit.runners.JUnit4; |
| 22 | |
| 23 | |
| 24 | @RunWith(JUnit4.class) |
| 25 | public class TestBenchmarkSamples { |
| 26 | |
| 27 | private final ObjectMapper mapper = new ObjectMapper(); |
| 28 | private final int rounds = 1000; |
| 29 | private long t1 = 0, t2 = 0; |
| 30 | |
| Akron | 09ae373 | 2015-08-13 20:56:20 +0200 | [diff] [blame] | 31 | |
| Akron | 98b7854 | 2015-08-06 21:43:08 +0200 | [diff] [blame] | 32 | @Test |
| 33 | public void simpleSegmentQuery () throws Exception { |
| 34 | // Construct index |
| 35 | |
| 36 | KrillIndex ki = new KrillIndex(); |
| 37 | |
| 38 | // Indexing test files |
| 39 | for (String i : new String[] { "00001", "00002", "00003", "00004", |
| Akron | 09ae373 | 2015-08-13 20:56:20 +0200 | [diff] [blame] | 40 | "00005", "00006", "02439" }) { |
| Akron | 98b7854 | 2015-08-06 21:43:08 +0200 | [diff] [blame] | 41 | ki.addDoc( |
| Akron | 09ae373 | 2015-08-13 20:56:20 +0200 | [diff] [blame] | 42 | getClass().getResourceAsStream("/wiki/" + i + ".json.gz"), |
| 43 | true); |
| Akron | 98b7854 | 2015-08-06 21:43:08 +0200 | [diff] [blame] | 44 | }; |
| 45 | ki.commit(); |
| 46 | |
| 47 | t1 = System.nanoTime(); |
| 48 | for (int i = 1; i <= rounds; i++) { |
| 49 | final QueryBuilder qb = new QueryBuilder("tokens"); |
| 50 | final Krill ks = new Krill(qb.seg("mate/m:gender:masc").toQuery()); |
| 51 | final Result kr = ks.apply(ki); |
| 52 | assertEquals(kr.getTotalResults(), 497); |
| 53 | }; |
| 54 | t2 = System.nanoTime(); |
| 55 | double seconds = (double) (t2 - t1) / 1000000000.0; |
| 56 | System.err.println("Seconds: " + seconds); |
| 57 | |
| 58 | // Seconds: 9.465514311 |
| 59 | // Seconds: 9.302011468 |
| 60 | // Seconds: 9.052496918 |
| 61 | // Seconds: 9.0567007 |
| 62 | // Seconds: 9.113724089 |
| 63 | // Seconds: 8.700548842 |
| 64 | // Seconds: 9.390980437 |
| 65 | // Seconds: 8.817503952 |
| 66 | }; |
| 67 | }; |