Path: blob/master/test/micro/org/openjdk/bench/javax/xml/STAX.java
41159 views
/*1* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22package org.openjdk.bench.javax.xml;2324import org.openjdk.jmh.annotations.Benchmark;25import org.openjdk.jmh.annotations.Level;26import org.openjdk.jmh.annotations.Setup;27import org.openjdk.jmh.annotations.TearDown;2829import javax.xml.stream.XMLInputFactory;30import javax.xml.stream.XMLStreamConstants;31import javax.xml.stream.XMLStreamReader;32import java.io.ByteArrayInputStream;33import java.util.HashMap;34import java.util.LinkedList;35import java.util.Map;3637public class STAX extends AbstractXMLMicro {3839/** Live data */40public Map<String, LinkedList<String>> liveData;4142@Setup(Level.Iteration)43public void setupLiveData() {44Map<String, LinkedList<String>> map = new HashMap<>();45// Somewhere around 100 MB live, but fragmented to start with.46for (int i = 0; i < 1000; i++) {47LinkedList<String> list = new LinkedList<>();48String key = "Dummy linked list " + i;49list.add(key);50for (int j = 0; j < 1000; j++) {51list.add("Dummy string " + i + "." + j);52}53map.put(key, list);54}55// thread safe, will only be one56liveData = map;57}5859@TearDown(Level.Iteration)60public void teardownLiveData() {61liveData = null;62}6364@Benchmark65public int testParse() throws Exception {66int intDummy = 0;67byte[] bytes = getFileBytesFromResource(doc);68ByteArrayInputStream bais = new ByteArrayInputStream(bytes);69XMLInputFactory factory = XMLInputFactory.newInstance();7071XMLStreamReader parser = factory.createXMLStreamReader(bais);72int acc;73do {74acc = parser.next();75intDummy += acc;76} while (acc != XMLStreamConstants.END_DOCUMENT);77return intDummy;78}7980}818283