blob: e0c1d8f7ee809a46820e36e138b2c22f70038d2b (
plain) (
blame)
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
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.test;
import com.yahoo.search.Query;
/**
* Tests the speed of accessing the query
*
* @author bratseth
*/
public class QueryBenchmark {
public void run() {
int result=0;
// Warm-up
out("Warming up...");
for (int i=0; i<10*1000; i++)
result+=createAndAccessQuery(i);
long startTime=System.currentTimeMillis();
out("Running...");
for (int i=0; i<100*1000; i++)
result+=createAndAccessQuery(i);
out("Ignore this: " + result); // Make sure we are not fooled by optimization by creating an observable result
long endTime=System.currentTimeMillis();
out("Creating and accessing a query 100.000 times took " + (endTime-startTime) + " ms");
}
private final int createAndAccessQuery(int i) {
// 8 sets, 8 gets
Query query=new Query("?query=test&hits=10&presentation.bolding=true&model.type=all");
query.properties().set("model.defaultIndex","title");
query.properties().set("string1","value1:" + i);
query.properties().set("string2","value2:" + i);
query.properties().set("string3","value3:" + i);
int result=((String)query.properties().get("string1")).length();
result+=((String)query.properties().get("string2")).length();
result+=((String)query.properties().get("string3")).length();
result+=((String)query.properties().get("model.defaultIndex")).length();
Query clone=query.clone();
result+=((String)query.properties().get("string1")).length();
result+=((String)query.properties().get("string2")).length();
result+=((String)query.properties().get("string3")).length();
result+=((String)clone.properties().get("model.defaultIndex")).length();
return result;
}
private void out(String string) {
System.out.println(string);
}
public static void main(String[] args) {
new QueryBenchmark().run();
}
}
|