bug 58896: write autoSizeColumn timing to POILogger instead of standard output

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1739584 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Javen O'Neal 2016-04-17 11:36:50 +00:00
parent e678eeb582
commit e66fc6b289

View File

@ -39,6 +39,8 @@ import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.SheetUtil; import org.apache.poi.ss.util.SheetUtil;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
import org.junit.Assume; import org.junit.Assume;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
@ -50,6 +52,8 @@ import org.junit.Test;
*/ */
public abstract class BaseTestBugzillaIssues { public abstract class BaseTestBugzillaIssues {
private static final POILogger logger = POILogFactory.getLogger(BaseTestBugzillaIssues.class);
private final ITestDataProvider _testDataProvider; private final ITestDataProvider _testDataProvider;
protected BaseTestBugzillaIssues(ITestDataProvider testDataProvider) { protected BaseTestBugzillaIssues(ITestDataProvider testDataProvider) {
@ -1427,12 +1431,13 @@ public abstract class BaseTestBugzillaIssues {
public void test58896() throws IOException { public void test58896() throws IOException {
final int nrows = 160; final int nrows = 160;
final int ncols = 139; final int ncols = 139;
final java.io.PrintStream out = System.out;
// Create a workbook // Create a workbook
final Workbook wb = _testDataProvider.createWorkbook(nrows+1); final Workbook wb = _testDataProvider.createWorkbook(nrows+1);
final Sheet sh = wb.createSheet(); final Sheet sh = wb.createSheet();
out.println(wb.getClass().getName() + " column autosizing timing..."); if (logger.check(POILogger.DEBUG)) {
logger.log(POILogger.DEBUG, wb.getClass().getName() + " column autosizing timing...");
}
final long t0 = time(); final long t0 = time();
_testDataProvider.trackAllColumnsForAutosizing(sh); _testDataProvider.trackAllColumnsForAutosizing(sh);
@ -1445,24 +1450,33 @@ public abstract class BaseTestBugzillaIssues {
} }
final double populateSheetTime = delta(t0); final double populateSheetTime = delta(t0);
final double populateSheetTimePerCell_ns = (1000000 * populateSheetTime / (nrows*ncols)); final double populateSheetTimePerCell_ns = (1000000 * populateSheetTime / (nrows*ncols));
out.println("Populate sheet time: " + populateSheetTime + " ms (" + populateSheetTimePerCell_ns + " ns/cell)"); if (logger.check(POILogger.DEBUG)) {
logger.log(POILogger.DEBUG, "Populate sheet time: " + populateSheetTime + " ms (" + populateSheetTimePerCell_ns + " ns/cell)");
out.println("\nAutosizing..."); logger.log(POILogger.DEBUG, "Autosizing...");
}
final long t1 = time(); final long t1 = time();
for (int c=0; c<ncols; c++) { for (int c=0; c<ncols; c++) {
final long t2 = time(); final long t2 = time();
sh.autoSizeColumn(c); sh.autoSizeColumn(c);
out.println("Column " + c + " took " + delta(t2) + " ms"); if (logger.check(POILogger.DEBUG)) {
logger.log(POILogger.DEBUG, "Column " + c + " took " + delta(t2) + " ms");
}
} }
final double autoSizeColumnsTime = delta(t1); final double autoSizeColumnsTime = delta(t1);
final double autoSizeColumnsTimePerColumn = autoSizeColumnsTime / ncols; final double autoSizeColumnsTimePerColumn = autoSizeColumnsTime / ncols;
final double bestFitWidthTimePerCell_ns = 1000000 * autoSizeColumnsTime / (ncols * nrows); final double bestFitWidthTimePerCell_ns = 1000000 * autoSizeColumnsTime / (ncols * nrows);
out.println("Auto sizing columns took a total of " + autoSizeColumnsTime + " ms (" + autoSizeColumnsTimePerColumn + " ms per column)"); if (logger.check(POILogger.DEBUG)) {
out.println("Best fit width time per cell: " + bestFitWidthTimePerCell_ns + " ns"); logger.log(POILogger.DEBUG, "Auto sizing columns took a total of " + autoSizeColumnsTime + " ms (" + autoSizeColumnsTimePerColumn + " ms per column)");
logger.log(POILogger.DEBUG, "Best fit width time per cell: " + bestFitWidthTimePerCell_ns + " ns");
}
final double totalTime_s = (populateSheetTime + autoSizeColumnsTime) / 1000; final double totalTime_s = (populateSheetTime + autoSizeColumnsTime) / 1000;
out.println("Total time: " + totalTime_s + " s"); if (logger.check(POILogger.DEBUG)) {
logger.log(POILogger.DEBUG, "Total time: " + totalTime_s + " s");
}
wb.close(); wb.close();