blob: 7a9f5ce59b6a2af96db1ffcba86e7e5994dae1b7 (
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
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.query.test;
import com.yahoo.prelude.query.WeightedSetItem;
import com.yahoo.search.Query;
/**
* @author <a href="mailto:bratseth@yahoo-inc.com">Jon Bratseth</a>
*/
public class QueryCloneMicroBenchmark {
public void benchmark() {
int runs = 10000;
Query query = createQuery();
for (int i = 0; i<100000; i++) // yes, this much is needed
query.clone();
long startTime = System.currentTimeMillis();
for (int i = 0; i<runs; i++)
query.clone();
long totalTime = System.currentTimeMillis() - startTime;
System.out.println("Time per clone: " + (totalTime * 1000 * 1000 / runs) + " nanoseconds" );
}
private Query createQuery() {
Query query = new Query();
query.getModel().getQueryTree().setRoot(createWeightedSet());
return query;
}
private WeightedSetItem createWeightedSet() {
WeightedSetItem item = new WeightedSetItem("w");
for (int i = 0; i<1000; i++)
item.addToken("item" + i, i);
return item;
}
public static void main(String[] args) {
new QueryCloneMicroBenchmark().benchmark();
}
}
|