From 2dbede0ef5c24f3324b0456b5f76fcd451bac2b7 Mon Sep 17 00:00:00 2001 From: azerr Date: Fri, 24 May 2019 17:46:17 +0200 Subject: [PATCH] Improve memory (see #389) --- .../performance/XMLScannerPerformance.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/performance/XMLScannerPerformance.java diff --git a/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/performance/XMLScannerPerformance.java b/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/performance/XMLScannerPerformance.java new file mode 100644 index 0000000000..502200f56b --- /dev/null +++ b/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/performance/XMLScannerPerformance.java @@ -0,0 +1,46 @@ +/******************************************************************************* +* Copyright (c) 2019 Red Hat Inc. and others. +* All rights reserved. This program and the accompanying materials +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v20.html +* +* Contributors: +* Red Hat Inc. - initial API and implementation +*******************************************************************************/ +package org.eclipse.lsp4xml.performance; + +import java.io.InputStream; + +import org.eclipse.lsp4xml.dom.DOMDocumentTest; +import org.eclipse.lsp4xml.dom.parser.Scanner; +import org.eclipse.lsp4xml.dom.parser.TokenType; +import org.eclipse.lsp4xml.dom.parser.XMLScanner; + +/** + * This utility class is used to check memories with use of XMLScanner with the big file nasa.xml. + * + * @author Angelo Zerr + * + */ +public class XMLScannerPerformance { + + public static void main(String[] args) { + InputStream in = DOMDocumentTest.class.getResourceAsStream("/xml/nasa.xml"); + String text = convertStreamToString(in); + // Parse every time the big file with scanner. + while (true) { + long start = System.currentTimeMillis(); + Scanner scanner = XMLScanner.createScanner(text); + TokenType token = scanner.scan(); + while (token != TokenType.EOS) { + token = scanner.scan(); + } + System.err.println("Parsed 'nasa.xml' with XMLScanner in " + (System.currentTimeMillis() - start) + " ms."); + } + } + + static String convertStreamToString(InputStream is) { + java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A"); + return s.hasNext() ? s.next() : ""; + } +}