summaryrefslogtreecommitdiffstats
path: root/src/examples
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2016-05-05 12:22:16 +0000
committerDominik Stadler <centic@apache.org>2016-05-05 12:22:16 +0000
commit12c0cb5314f021db9e614c67edf61f3c142edc7b (patch)
treed6dce850ca7dd710459111e4be130ad64d7c17ac /src/examples
parent4a4e60d1346926c079259652d38267c42267e8d1 (diff)
downloadpoi-12c0cb5314f021db9e614c67edf61f3c142edc7b.tar.gz
poi-12c0cb5314f021db9e614c67edf61f3c142edc7b.zip
Refactor SSPerformanceTest into a few methods to make it easier to use a profiler
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1742420 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/examples')
-rw-r--r--src/examples/src/org/apache/poi/ss/examples/SSPerformanceTest.java120
1 files changed, 67 insertions, 53 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 4d6dee448b..eb7532c7b4 100644
--- a/src/examples/src/org/apache/poi/ss/examples/SSPerformanceTest.java
+++ b/src/examples/src/org/apache/poi/ss/examples/SSPerformanceTest.java
@@ -44,6 +44,17 @@ public class SSPerformanceTest {
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);
+
+ if (saveFile) {
+ String fileName = type + "_" + rows + "_" + cols + "." + getFileSuffix(args[0]);
+ saveFile(workBook, fileName);
+ }
+ long timeFinished = System.currentTimeMillis();
+ System.out.println("Elapsed " + (timeFinished-timeStarted)/1000 + " seconds");
+ }
+
+ private static void addContent(Workbook workBook, boolean isHType, int rows, int cols) {
Map<String, CellStyle> styles = createStyles(workBook);
Sheet sheet = workBook.createSheet("Main Sheet");
@@ -68,63 +79,66 @@ public class SSPerformanceTest {
Row row = sheet.createRow(rowIndexInSheet);
for (int colIndex = 0; colIndex < cols; colIndex++) {
- Cell cell = row.createCell(colIndex);
- String address = new CellReference(cell).formatAsString();
- switch (colIndex){
- case 0:
- // column A: default number format
- cell.setCellValue(value++);
- break;
- case 1:
- // column B: #,##0
- cell.setCellValue(value++);
- cell.setCellStyle(styles.get("#,##0.00"));
- break;
- case 2:
- // column C: $#,##0.00
- cell.setCellValue(value++);
- cell.setCellStyle(styles.get("$#,##0.00"));
- break;
- case 3:
- // column D: red bold text on yellow background
- cell.setCellValue(address);
- cell.setCellStyle(styles.get("red-bold"));
- break;
- case 4:
- // column E: boolean
- // TODO booleans are shown as 1/0 instead of TRUE/FALSE
- cell.setCellValue(rowIndex % 2 == 0);
- break;
- case 5:
- // column F: date / time
- cell.setCellValue(calendar);
- cell.setCellStyle(styles.get("m/d/yyyy"));
- calendar.roll(Calendar.DAY_OF_YEAR, -1);
- break;
- case 6:
- // column F: formula
- // TODO formulas are not yet supported in SXSSF
- //cell.setCellFormula("SUM(A" + (rowIndex+1) + ":E" + (rowIndex+1)+ ")");
- //break;
- default:
- cell.setCellValue(value++);
- break;
- }
+ value = populateCell(styles, value, calendar, rowIndex, row, colIndex);
}
rowIndexInSheet++;
}
- if (saveFile) {
- String fileName = type + "_" + rows + "_" + cols + "." + getFileSuffix(args[0]);
- try {
- FileOutputStream out = new FileOutputStream(fileName);
- workBook.write(out);
- out.close();
- } catch (IOException ioe) {
- System.err.println("Error: failed to write to file \"" + fileName + "\", reason=" + ioe.getMessage());
- }
+ }
+
+ private static double populateCell(Map<String, CellStyle> styles, double value, Calendar calendar, int rowIndex, Row row, int colIndex) {
+ Cell cell = row.createCell(colIndex);
+ String address = new CellReference(cell).formatAsString();
+ switch (colIndex){
+ case 0:
+ // column A: default number format
+ cell.setCellValue(value++);
+ break;
+ case 1:
+ // column B: #,##0
+ cell.setCellValue(value++);
+ cell.setCellStyle(styles.get("#,##0.00"));
+ break;
+ case 2:
+ // column C: $#,##0.00
+ cell.setCellValue(value++);
+ cell.setCellStyle(styles.get("$#,##0.00"));
+ break;
+ case 3:
+ // column D: red bold text on yellow background
+ cell.setCellValue(address);
+ cell.setCellStyle(styles.get("red-bold"));
+ break;
+ case 4:
+ // column E: boolean
+ // TODO booleans are shown as 1/0 instead of TRUE/FALSE
+ cell.setCellValue(rowIndex % 2 == 0);
+ break;
+ case 5:
+ // column F: date / time
+ cell.setCellValue(calendar);
+ cell.setCellStyle(styles.get("m/d/yyyy"));
+ calendar.roll(Calendar.DAY_OF_YEAR, -1);
+ break;
+ case 6:
+ // column F: formula
+ // TODO formulas are not yet supported in SXSSF
+ //cell.setCellFormula("SUM(A" + (rowIndex+1) + ":E" + (rowIndex+1)+ ")");
+ //break;
+ default:
+ cell.setCellValue(value++);
+ break;
+ }
+ return value;
+ }
+
+ private static void saveFile(Workbook workBook, String fileName) {
+ try {
+ FileOutputStream out = new FileOutputStream(fileName);
+ workBook.write(out);
+ out.close();
+ } catch (IOException ioe) {
+ System.err.println("Error: failed to write to file \"" + fileName + "\", reason=" + ioe.getMessage());
}
- long timeFinished = System.currentTimeMillis();
- System.out.println("Elapsed " + (timeFinished-timeStarted)/1000 + " seconds");
}
static Map<String, CellStyle> createStyles(Workbook wb) {