aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2017-12-28 10:53:40 +0000
committerDominik Stadler <centic@apache.org>2017-12-28 10:53:40 +0000
commit9c288abff0b08049b4bf8e30c3ddb6c3cb7d80e5 (patch)
tree7cc6785313f04c29e0bf312270dfe0e657cc88cd
parent8197a53eca735049b32fa5338cf9ab104d478477 (diff)
downloadpoi-9c288abff0b08049b4bf8e30c3ddb6c3cb7d80e5.tar.gz
poi-9c288abff0b08049b4bf8e30c3ddb6c3cb7d80e5.zip
Bug 61665: Enhance SSPerformanceTest some more to add a warmup run and allow to run with unsynchronized XmlBeans
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1819417 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/examples/src/org/apache/poi/ss/examples/SSPerformanceTest.java54
1 files changed, 38 insertions, 16 deletions
diff --git a/src/examples/src/org/apache/poi/ss/examples/SSPerformanceTest.java b/src/examples/src/org/apache/poi/ss/examples/SSPerformanceTest.java
index 30a1dccb7f..1985e1f817 100644
--- a/src/examples/src/org/apache/poi/ss/examples/SSPerformanceTest.java
+++ b/src/examples/src/org/apache/poi/ss/examples/SSPerformanceTest.java
@@ -20,10 +20,12 @@ package org.apache.poi.ss.examples;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.util.Arrays;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
+import org.apache.poi.POIXMLTypeLoader;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
@@ -42,27 +44,47 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class SSPerformanceTest {
public static void main(String[] args) throws IOException {
- if (args.length != 4) usage("need four command arguments");
+ if (args.length < 4) {
+ usage("need at least four command arguments");
+ }
String type = args[0];
- long timeStarted = System.currentTimeMillis();
- Workbook workBook = createWorkbook(type);
- boolean isHType = workBook instanceof HSSFWorkbook;
-
int rows = parseInt(args[1], "Failed to parse rows value as integer");
int cols = parseInt(args[2], "Failed to parse cols value as integer");
boolean saveFile = parseInt(args[3], "Failed to parse saveFile value as integer") != 0;
- addContent(workBook, isHType, rows, cols);
+ boolean warmup = false;
+ for(int arg = 4; arg < args.length;arg++) {
+ if(args[arg].equals("--unsynchronized-xmlbeans")) {
+ POIXMLTypeLoader.DEFAULT_XML_OPTIONS.setUnsynchronized();
+ }
+ if(args[arg].equals("--with-warmup-run")) {
+ warmup = true;
+ }
+ }
- if (saveFile) {
- String fileName = type + "_" + rows + "_" + cols + "." + getFileSuffix(args[0]);
- saveFile(workBook, fileName);
+ if(warmup) {
+ System.out.println("Performing a warmup run first");
+ runWithArgs(type, rows, cols, saveFile);
}
+
+ long timeStarted = System.currentTimeMillis();
+ runWithArgs(type, rows, cols, saveFile);
long timeFinished = System.currentTimeMillis();
- System.out.println("Elapsed " + (timeFinished-timeStarted)/1000 + " seconds");
-
- workBook.close();
+
+ System.out.printf("Elapsed %.2f seconds for arguments %s\n", ((double)timeFinished - timeStarted) / 1000, Arrays.toString(args));
+ }
+
+ private static void runWithArgs(String type, int rows, int cols, boolean saveFile) throws IOException {
+ try (Workbook workBook = createWorkbook(type)) {
+ boolean isHType = workBook instanceof HSSFWorkbook;
+ addContent(workBook, isHType, rows, cols);
+
+ if (saveFile) {
+ String fileName = type + "_" + rows + "_" + cols + "." + getFileSuffix(type);
+ saveFile(workBook, fileName);
+ }
+ }
}
private static void addContent(Workbook workBook, boolean isHType, int rows, int cols) {
@@ -192,7 +214,7 @@ public class SSPerformanceTest {
static void usage(String message) {
System.err.println(message);
- System.err.println("usage: java SSPerformanceTest HSSF|XSSF|SXSSF rows cols saveFile (0|1)? ");
+ System.err.println("usage: java SSPerformanceTest HSSF|XSSF|SXSSF rows cols saveFile (0|1)? [--unsynchronized-xmlbeans] [--with-warmup-run]");
System.exit(1);
}
@@ -203,9 +225,9 @@ public class SSPerformanceTest {
return new XSSFWorkbook();
else if ("SXSSF".equals(type))
return new SXSSFWorkbook();
- else
- usage("Unknown type \"" + type + "\"");
- return null;
+
+ usage("Unknown type \"" + type + "\"");
+ throw new IllegalArgumentException("Should not reach this point");
}
static String getFileSuffix(String type) {