bug 58896: add unit test to time Sheet.autoSizeColumn
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1730997 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5e52b6f4e9
commit
57ebf6b133
@ -87,6 +87,14 @@ public final class SXSSFITestDataProvider implements ITestDataProvider {
|
||||
return wb;
|
||||
}
|
||||
|
||||
//************ SXSSF-specific methods ***************//
|
||||
@Override
|
||||
public SXSSFWorkbook createWorkbook(int rowAccessWindowSize) {
|
||||
SXSSFWorkbook wb = new SXSSFWorkbook(rowAccessWindowSize);
|
||||
instances.add(wb);
|
||||
return wb;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trackColumnsForAutosizing(Sheet sheet, int...columns) {
|
||||
for (int cn : columns) {
|
||||
@ -94,6 +102,12 @@ public final class SXSSFITestDataProvider implements ITestDataProvider {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trackAllColumnsForAutosizing(Sheet sheet) {
|
||||
((SXSSFSheet)sheet).trackAllColumnsForAutoSizing();
|
||||
}
|
||||
//************ End SXSSF-specific methods ***************//
|
||||
|
||||
@Override
|
||||
public FormulaEvaluator createFormulaEvaluator(Workbook wb) {
|
||||
return new XSSFFormulaEvaluator(((SXSSFWorkbook) wb).getXSSFWorkbook());
|
||||
|
@ -54,8 +54,17 @@ public final class XSSFITestDataProvider implements ITestDataProvider {
|
||||
return new XSSFWorkbook();
|
||||
}
|
||||
|
||||
//************ SXSSF-specific methods ***************//
|
||||
@Override
|
||||
public XSSFWorkbook createWorkbook(int rowAccessWindowSize) {
|
||||
return createWorkbook();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trackColumnsForAutosizing(Sheet sheet, int...columns) {}
|
||||
@Override
|
||||
public void trackAllColumnsForAutosizing(Sheet sheet) {}
|
||||
//************ End SXSSF-specific methods ***************//
|
||||
|
||||
@Override
|
||||
public FormulaEvaluator createFormulaEvaluator(Workbook wb) {
|
||||
|
@ -60,8 +60,17 @@ public final class HSSFITestDataProvider implements ITestDataProvider {
|
||||
return new HSSFWorkbook();
|
||||
}
|
||||
|
||||
//************ SXSSF-specific methods ***************//
|
||||
@Override
|
||||
public HSSFWorkbook createWorkbook(int rowAccessWindowSize) {
|
||||
return createWorkbook();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trackColumnsForAutosizing(Sheet sheet, int...columns) {}
|
||||
@Override
|
||||
public void trackAllColumnsForAutosizing(Sheet sheet) {}
|
||||
//************ End SXSSF-specific methods ***************//
|
||||
|
||||
@Override
|
||||
public FormulaEvaluator createFormulaEvaluator(Workbook wb) {
|
||||
|
@ -47,11 +47,22 @@ public interface ITestDataProvider {
|
||||
*/
|
||||
Workbook createWorkbook();
|
||||
|
||||
|
||||
//************ SXSSF-specific methods ***************//
|
||||
/**
|
||||
* Provides way of creating a SXSSFWorkbook with a specific row access window size.
|
||||
* Equivalent to createWorkbook on others.
|
||||
* @return an instance of Workbook
|
||||
*/
|
||||
Workbook createWorkbook(int rowAccessWindowSize);
|
||||
|
||||
/**
|
||||
* Only matters for SXSSF - enables tracking of the column
|
||||
* widths so that autosizing can work. No-op on others.
|
||||
*/
|
||||
void trackColumnsForAutosizing(Sheet sheet, int...columns);
|
||||
void trackAllColumnsForAutosizing(Sheet sheet);
|
||||
//************ End SXSSF-specific methods ***************//
|
||||
|
||||
/**
|
||||
* Creates the corresponding {@link FormulaEvaluator} for the
|
||||
|
@ -1427,4 +1427,64 @@ public abstract class BaseTestBugzillaIssues {
|
||||
|
||||
assertEquals("12-312-345-123", formatter.formatCellValue(cell));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test58896() throws IOException {
|
||||
final int nrows = 160;
|
||||
final int ncols = 139;
|
||||
final java.io.PrintStream out = System.out;
|
||||
|
||||
// Create a workbook
|
||||
final Workbook wb = _testDataProvider.createWorkbook(nrows+1);
|
||||
final Sheet sh = wb.createSheet();
|
||||
out.println(wb.getClass().getName() + " column autosizing timing...");
|
||||
|
||||
final long t0 = time();
|
||||
_testDataProvider.trackAllColumnsForAutosizing(sh);
|
||||
for (int r=0; r<nrows; r++) {
|
||||
final Row row = sh.createRow(r);
|
||||
for (int c=0; c<ncols; c++) {
|
||||
final Cell cell = row.createCell(c);
|
||||
cell.setCellValue("Cell[r="+r+",c="+c+"]");
|
||||
}
|
||||
}
|
||||
final double populateSheetTime = delta(t0);
|
||||
final double populateSheetTimePerCell_ns = (1000000 * populateSheetTime / (nrows*ncols));
|
||||
out.println("Populate sheet time: " + populateSheetTime + " ms (" + populateSheetTimePerCell_ns + " ns/cell)");
|
||||
|
||||
out.println("\nAutosizing...");
|
||||
final long t1 = time();
|
||||
for (int c=0; c<ncols; c++) {
|
||||
final long t2 = time();
|
||||
sh.autoSizeColumn(c);
|
||||
out.println("Column " + c + " took " + delta(t2) + " ms");
|
||||
}
|
||||
final double autoSizeColumnsTime = delta(t1);
|
||||
final double autoSizeColumnsTimePerColumn = autoSizeColumnsTime / ncols;
|
||||
final double bestFitWidthTimePerCell_ns = 1000000 * autoSizeColumnsTime / (ncols * nrows);
|
||||
|
||||
out.println("Auto sizing columns took a total of " + autoSizeColumnsTime + " ms (" + autoSizeColumnsTimePerColumn + " ms per column)");
|
||||
out.println("Best fit width time per cell: " + bestFitWidthTimePerCell_ns + " ns");
|
||||
|
||||
final double totalTime_s = (populateSheetTime + autoSizeColumnsTime) / 1000;
|
||||
out.println("Total time: " + totalTime_s + " s");
|
||||
|
||||
wb.close();
|
||||
|
||||
//if (bestFitWidthTimePerCell_ns > 50000) {
|
||||
// fail("Best fit width time per cell exceeded 50000 ns: " + bestFitWidthTimePerCell_ns + " ns");
|
||||
//}
|
||||
|
||||
if (totalTime_s > 10) {
|
||||
fail("Total time exceeded 10 seconds: " + totalTime_s + " s");
|
||||
}
|
||||
}
|
||||
|
||||
public long time() {
|
||||
final long currentTime = System.currentTimeMillis();
|
||||
return currentTime;
|
||||
}
|
||||
public double delta(long startTimeMillis) {
|
||||
return time() - startTimeMillis;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user