summaryrefslogtreecommitdiff
path: root/morfologik-polish/src/test/java/morfologik/stemming/PerformanceTest.java
blob: d93216db6976871c9df956150f2cdb2fca19e4bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package morfologik.stemming;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;

import org.junit.BeforeClass;
import org.junit.Test;

import com.carrotsearch.junitbenchmarks.AbstractBenchmark;
import com.carrotsearch.junitbenchmarks.BenchmarkOptions;

/**
 * Simple performance micro-benchmarks.
 */
@BenchmarkOptions(callgc = false, warmupRounds = 5, benchmarkRounds = 10)
public class PerformanceTest extends AbstractBenchmark {
	/* Guard against escape analysis and HotSpot opts. */
	public volatile int guard;

	/* Test data. */
	static final int sequences = 100000;
	static final String[] testWords = new String[sequences];
	static final PolishStemmer stemmer = new PolishStemmer();

	/**
	 * Prepare test data.
	 */
	@BeforeClass
	public static void prepare() throws UnsupportedEncodingException
	{
		final Dictionary dict = Dictionary.getForLanguage("pl");
		int i = 0;
		for (ByteBuffer sequence : dict.fsa) {
			testWords[i] = new String(sequence.array(), 0,
			        sequence.remaining(), dict.metadata.getEncoding());
			testWords[i] = testWords[i].substring(0, testWords[i]
			        .indexOf(dict.metadata.getSeparator()));
			i++;

			if (i == testWords.length)
				break;
		}
	}
	
	@Test
	public void traversal_100000() throws IOException {
		final Dictionary dict = Dictionary.getForLanguage("pl");

		int max = sequences;
		int guard = 0;
		for (ByteBuffer sequence : dict.fsa) {
			guard += sequence.remaining();
			if (--max == 0)
				break;
		}

		this.guard = guard;
	}

	@Test
	public void stemming_100000() throws IOException {
		int guard = 0;
		for (String word : testWords) {
			for (WordData dta : stemmer.lookup(word))
			{
				guard += dta.getStem().length();
				guard += dta.getTag().length();
			}
		}
		this.guard = guard;
	}
}