-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f549ca7
commit 2dbede0
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/performance/XMLScannerPerformance.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() : ""; | ||
} | ||
} |