Skip to content

Commit

Permalink
Improve memory (see #389)
Browse files Browse the repository at this point in the history
  • Loading branch information
angelozerr committed May 24, 2019
1 parent f549ca7 commit 2dbede0
Showing 1 changed file with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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() : "";
}
}

0 comments on commit 2dbede0

Please sign in to comment.