author | herrick |
Tue, 09 Apr 2019 16:06:21 -0400 | |
branch | JDK-8200758-branch |
changeset 57316 | 2891b3ae222d |
parent 52595 | 16609197022c |
permissions | -rw-r--r-- |
52595
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
1 |
/* |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
2 |
* Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
4 |
* |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
8 |
* |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
13 |
* accompanied this code). |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
14 |
* |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
18 |
* |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
21 |
* questions. |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
22 |
*/ |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
23 |
package org.openjdk.bench.javax.xml; |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
24 |
|
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
25 |
import org.openjdk.jmh.annotations.Benchmark; |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
26 |
import org.openjdk.jmh.annotations.Level; |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
27 |
import org.openjdk.jmh.annotations.Setup; |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
28 |
import org.openjdk.jmh.annotations.TearDown; |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
29 |
|
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
30 |
import javax.xml.stream.XMLInputFactory; |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
31 |
import javax.xml.stream.XMLStreamConstants; |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
32 |
import javax.xml.stream.XMLStreamReader; |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
33 |
import java.io.ByteArrayInputStream; |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
34 |
import java.util.HashMap; |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
35 |
import java.util.LinkedList; |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
36 |
import java.util.Map; |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
37 |
|
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
38 |
public class STAX extends AbstractXMLMicro { |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
39 |
|
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
40 |
/** Live data */ |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
41 |
public Map<String, LinkedList<String>> liveData; |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
42 |
|
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
43 |
@Setup(Level.Iteration) |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
44 |
public void setupLiveData() { |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
45 |
Map<String, LinkedList<String>> map = new HashMap<>(); |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
46 |
// Somewhere around 100 MB live, but fragmented to start with. |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
47 |
for (int i = 0; i < 1000; i++) { |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
48 |
LinkedList<String> list = new LinkedList<>(); |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
49 |
String key = "Dummy linked list " + i; |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
50 |
list.add(key); |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
51 |
for (int j = 0; j < 1000; j++) { |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
52 |
list.add("Dummy string " + i + "." + j); |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
53 |
} |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
54 |
map.put(key, list); |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
55 |
} |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
56 |
// thread safe, will only be one |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
57 |
liveData = map; |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
58 |
} |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
59 |
|
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
60 |
@TearDown(Level.Iteration) |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
61 |
public void teardownLiveData() { |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
62 |
liveData = null; |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
63 |
} |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
64 |
|
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
65 |
@Benchmark |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
66 |
public int testParse() throws Exception { |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
67 |
int intDummy = 0; |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
68 |
byte[] bytes = getFileBytesFromResource(doc); |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
69 |
ByteArrayInputStream bais = new ByteArrayInputStream(bytes); |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
70 |
XMLInputFactory factory = XMLInputFactory.newInstance(); |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
71 |
|
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
72 |
XMLStreamReader parser = factory.createXMLStreamReader(bais); |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
73 |
int acc; |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
74 |
do { |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
75 |
acc = parser.next(); |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
76 |
intDummy += acc; |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
77 |
} while (acc != XMLStreamConstants.END_DOCUMENT); |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
78 |
return intDummy; |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
79 |
} |
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
80 |
|
16609197022c
8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff
changeset
|
81 |
} |