|
|
|
@ -3,20 +3,23 @@ package com.alibaba.easyexcel.test.core.large;
|
|
|
|
|
import java.io.File; |
|
|
|
|
import java.io.FileOutputStream; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Iterator; |
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
import com.alibaba.easyexcel.test.util.TestFileUtil; |
|
|
|
|
import com.alibaba.excel.EasyExcel; |
|
|
|
|
import com.alibaba.excel.ExcelWriter; |
|
|
|
|
import com.alibaba.excel.util.CostUtil; |
|
|
|
|
import com.alibaba.excel.write.handler.WriteHandler; |
|
|
|
|
import com.alibaba.excel.write.handler.context.CellWriteHandlerContext; |
|
|
|
|
import com.alibaba.excel.write.handler.impl.FillStyleCellWriteHandler; |
|
|
|
|
import com.alibaba.excel.write.metadata.WriteSheet; |
|
|
|
|
import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder; |
|
|
|
|
|
|
|
|
|
import org.apache.poi.xssf.streaming.SXSSFCell; |
|
|
|
|
import org.apache.poi.xssf.streaming.SXSSFRow; |
|
|
|
|
import org.apache.poi.xssf.streaming.SXSSFSheet; |
|
|
|
|
import org.apache.poi.xssf.streaming.SXSSFWorkbook; |
|
|
|
|
import org.junit.Assert; |
|
|
|
|
import org.junit.BeforeClass; |
|
|
|
|
import org.junit.FixMethodOrder; |
|
|
|
|
import org.junit.Test; |
|
|
|
@ -85,6 +88,54 @@ public class LargeDataTest {
|
|
|
|
|
LOGGER.info("CSV large data total time spent:{}", System.currentTimeMillis() - start); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void t04Write666() throws Exception { |
|
|
|
|
long start = System.currentTimeMillis(); |
|
|
|
|
ExcelWriter excelWriter = EasyExcel.write(fileWrite07, LargeData.class).build(); |
|
|
|
|
WriteSheet writeSheet = EasyExcel.writerSheet().build(); |
|
|
|
|
for (int j = 0; j < 2; j++) { |
|
|
|
|
excelWriter.write(data(), writeSheet); |
|
|
|
|
LOGGER.info("{} write success.", j); |
|
|
|
|
} |
|
|
|
|
excelWriter.finish(); |
|
|
|
|
long cost = System.currentTimeMillis() - start; |
|
|
|
|
LOGGER.info("write cost:{}", cost); |
|
|
|
|
|
|
|
|
|
start = System.currentTimeMillis(); |
|
|
|
|
excelWriter = EasyExcel.write(fileWrite07, LargeData.class).build(); |
|
|
|
|
writeSheet = EasyExcel.writerSheet().build(); |
|
|
|
|
for (int j = 0; j < 100; j++) { |
|
|
|
|
excelWriter.write(data(), writeSheet); |
|
|
|
|
LOGGER.info("{} write success.", j); |
|
|
|
|
} |
|
|
|
|
excelWriter.finish(); |
|
|
|
|
cost = System.currentTimeMillis() - start; |
|
|
|
|
LOGGER.info("write cost:{}", cost); |
|
|
|
|
start = System.currentTimeMillis(); |
|
|
|
|
try (FileOutputStream fileOutputStream = new FileOutputStream(fileWritePoi07)) { |
|
|
|
|
SXSSFWorkbook workbook = new SXSSFWorkbook(); |
|
|
|
|
SXSSFSheet sheet = workbook.createSheet("sheet1"); |
|
|
|
|
for (int i = 0; i < 100 * 5000; i++) { |
|
|
|
|
SXSSFRow row = sheet.createRow(i); |
|
|
|
|
for (int j = 0; j < 25; j++) { |
|
|
|
|
SXSSFCell cell = row.createCell(j); |
|
|
|
|
cell.setCellValue("str-" + j + "-" + i); |
|
|
|
|
} |
|
|
|
|
if (i % 5000 == 0) { |
|
|
|
|
LOGGER.info("{} write success.", i); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
workbook.write(fileOutputStream); |
|
|
|
|
workbook.dispose(); |
|
|
|
|
workbook.close(); |
|
|
|
|
} |
|
|
|
|
long costPoi = System.currentTimeMillis() - start; |
|
|
|
|
LOGGER.info("poi write cost:{}", System.currentTimeMillis() - start); |
|
|
|
|
LOGGER.info("{} vs {}", cost, costPoi); |
|
|
|
|
|
|
|
|
|
Assert.assertTrue(costPoi * 3 > cost); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void t04Write44() throws Exception { |
|
|
|
|
//read();
|
|
|
|
@ -132,110 +183,136 @@ public class LargeDataTest {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void t04Write() throws Exception { |
|
|
|
|
Cellhanderl cellhanderl1 = new Cellhanderl(); |
|
|
|
|
Cellhanderl cellhanderl2 = new Cellhanderl(); |
|
|
|
|
Cellhanderl cellhanderl3 = new Cellhanderl(); |
|
|
|
|
Cellhanderl cellhanderl4 = new Cellhanderl(); |
|
|
|
|
List<Cellhanderl> list = new ArrayList<>(); |
|
|
|
|
WriteHandler cellhanderl1 = new Cellhanderl(); |
|
|
|
|
WriteHandler cellhanderl2 = new Cellhanderl(); |
|
|
|
|
WriteHandler cellhanderl3 = new Cellhanderl(); |
|
|
|
|
WriteHandler cellhanderl4 = new Cellhanderl(); |
|
|
|
|
List<WriteHandler> list = new ArrayList<>(); |
|
|
|
|
list.add(cellhanderl1); |
|
|
|
|
list.add(cellhanderl2); |
|
|
|
|
list.add(cellhanderl3); |
|
|
|
|
|
|
|
|
|
//list.add(cellhanderl4);
|
|
|
|
|
|
|
|
|
|
long start = System.currentTimeMillis(); |
|
|
|
|
for (int i = 0; i < 25000075; i++) { |
|
|
|
|
for (int i = 0; i < 6250025; i++) { |
|
|
|
|
CellWriteHandlerContext content=new CellWriteHandlerContext(); |
|
|
|
|
content.setColumnIndex(99); |
|
|
|
|
for (int j = 0; j < list.size(); j++) { |
|
|
|
|
Cellhanderl writeHandler = list.get(0); |
|
|
|
|
writeHandler.beforeCellCreate(null); |
|
|
|
|
writeHandler.afterCellCreate(null); |
|
|
|
|
writeHandler.afterCellDataConverted(null); |
|
|
|
|
writeHandler.afterCellDispose(null); |
|
|
|
|
WriteHandler writeHandler = list.get(0); |
|
|
|
|
((Cellhanderl)writeHandler).beforeCellCreate(content); |
|
|
|
|
((Cellhanderl)writeHandler).afterCellCreate(content); |
|
|
|
|
((Cellhanderl)writeHandler).afterCellDataConverted(content); |
|
|
|
|
((Cellhanderl)writeHandler).afterCellDispose(content); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
LOGGER.info("第一次:{}", System.currentTimeMillis() - start); |
|
|
|
|
|
|
|
|
|
start = System.currentTimeMillis(); |
|
|
|
|
for (int i = 0; i < 25000075; i++) { |
|
|
|
|
for (Cellhanderl writeHandler : list) { |
|
|
|
|
writeHandler.beforeCellCreate(null); |
|
|
|
|
writeHandler.afterCellCreate(null); |
|
|
|
|
writeHandler.afterCellDataConverted(null); |
|
|
|
|
writeHandler.afterCellDispose(null); |
|
|
|
|
for (int i = 0; i < 6250025; i++) { |
|
|
|
|
CellWriteHandlerContext content=new CellWriteHandlerContext(); |
|
|
|
|
content.setColumnIndex(99); |
|
|
|
|
for (WriteHandler writeHandler : list) { |
|
|
|
|
|
|
|
|
|
((Cellhanderl)writeHandler).beforeCellCreate(content); |
|
|
|
|
((Cellhanderl)writeHandler).afterCellCreate(content); |
|
|
|
|
((Cellhanderl)writeHandler).afterCellDataConverted(content); |
|
|
|
|
((Cellhanderl)writeHandler).afterCellDispose(content); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
LOGGER.info("第二次:{}", System.currentTimeMillis() - start); |
|
|
|
|
//
|
|
|
|
|
//start = System.currentTimeMillis();
|
|
|
|
|
//for (int i = 0; i < 6250025; i++) {
|
|
|
|
|
// cellhanderl1.beforeCellCreate(null);
|
|
|
|
|
// cellhanderl1.afterCellCreate(null);
|
|
|
|
|
// cellhanderl1.afterCellDataConverted(null);
|
|
|
|
|
// cellhanderl1.afterCellDispose(null);
|
|
|
|
|
// cellhanderl2.beforeCellCreate(null);
|
|
|
|
|
// cellhanderl2.afterCellCreate(null);
|
|
|
|
|
// cellhanderl2.afterCellDataConverted(null);
|
|
|
|
|
// cellhanderl2.afterCellDispose(null);
|
|
|
|
|
// cellhanderl3.beforeCellCreate(null);
|
|
|
|
|
// cellhanderl3.afterCellCreate(null);
|
|
|
|
|
// cellhanderl3.afterCellDataConverted(null);
|
|
|
|
|
// cellhanderl3.afterCellDispose(null);
|
|
|
|
|
//
|
|
|
|
|
//}
|
|
|
|
|
//LOGGER.info("第三次:{}", System.currentTimeMillis() - start);
|
|
|
|
|
//
|
|
|
|
|
//start = System.currentTimeMillis();
|
|
|
|
|
//for (int i = 0; i < 25000075; i++) {
|
|
|
|
|
// Iterator<Cellhanderl> iterator = list.iterator();
|
|
|
|
|
// while (iterator.hasNext()) {
|
|
|
|
|
// Cellhanderl writeHandler = iterator.next();
|
|
|
|
|
// writeHandler.beforeCellCreate(null);
|
|
|
|
|
// writeHandler.afterCellCreate(null);
|
|
|
|
|
// writeHandler.afterCellDataConverted(null);
|
|
|
|
|
// writeHandler.afterCellDispose(null);
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
//
|
|
|
|
|
//LOGGER.info("第四次:{}", System.currentTimeMillis() - start);
|
|
|
|
|
//
|
|
|
|
|
//start = System.currentTimeMillis();
|
|
|
|
|
//for (int i = 0; i < 25000075; i++) {
|
|
|
|
|
// list.stream().forEach(writeHandler -> {
|
|
|
|
|
// writeHandler.beforeCellCreate(null);
|
|
|
|
|
// writeHandler.afterCellCreate(null);
|
|
|
|
|
// writeHandler.afterCellDataConverted(null);
|
|
|
|
|
// writeHandler.afterCellDispose(null);
|
|
|
|
|
// });
|
|
|
|
|
//}
|
|
|
|
|
//
|
|
|
|
|
//LOGGER.info("第五次:{}", System.currentTimeMillis() - start);
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
start = System.currentTimeMillis(); |
|
|
|
|
for (int i = 0; i < 25000075; i++) { |
|
|
|
|
private void v2(Cellhanderl cellhanderl1) { |
|
|
|
|
cellhanderl1.beforeCellCreate(null); |
|
|
|
|
cellhanderl1.afterCellCreate(null); |
|
|
|
|
cellhanderl1.afterCellDataConverted(null); |
|
|
|
|
cellhanderl1.afterCellDispose(null); |
|
|
|
|
cellhanderl2.beforeCellCreate(null); |
|
|
|
|
cellhanderl2.afterCellCreate(null); |
|
|
|
|
cellhanderl2.afterCellDataConverted(null); |
|
|
|
|
cellhanderl2.afterCellDispose(null); |
|
|
|
|
cellhanderl3.beforeCellCreate(null); |
|
|
|
|
cellhanderl3.afterCellCreate(null); |
|
|
|
|
cellhanderl3.afterCellDataConverted(null); |
|
|
|
|
cellhanderl3.afterCellDispose(null); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
LOGGER.info("第三次:{}", System.currentTimeMillis() - start); |
|
|
|
|
|
|
|
|
|
start = System.currentTimeMillis(); |
|
|
|
|
for (int i = 0; i < 25000075; i++) { |
|
|
|
|
Iterator<Cellhanderl> iterator = list.iterator(); |
|
|
|
|
while (iterator.hasNext()) { |
|
|
|
|
Cellhanderl writeHandler = iterator.next(); |
|
|
|
|
writeHandler.beforeCellCreate(null); |
|
|
|
|
writeHandler.afterCellCreate(null); |
|
|
|
|
writeHandler.afterCellDataConverted(null); |
|
|
|
|
writeHandler.afterCellDispose(null); |
|
|
|
|
} |
|
|
|
|
@Test |
|
|
|
|
public void t04Writev32() throws Exception { |
|
|
|
|
//System.setProperty(DebuggingClassWriter.DEBUG_LOCATION_PROPERTY, "/Users/zhuangjiaju/test");
|
|
|
|
|
//read();
|
|
|
|
|
Thread.sleep(10*1000); |
|
|
|
|
read(); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
LOGGER.info("第四次:{}", System.currentTimeMillis() - start); |
|
|
|
|
|
|
|
|
|
start = System.currentTimeMillis(); |
|
|
|
|
for (int i = 0; i < 25000075; i++) { |
|
|
|
|
list.stream().forEach(writeHandler->{ |
|
|
|
|
writeHandler.beforeCellCreate(null); |
|
|
|
|
writeHandler.afterCellCreate(null); |
|
|
|
|
writeHandler.afterCellDataConverted(null); |
|
|
|
|
writeHandler.afterCellDispose(null); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
@Test |
|
|
|
|
public void t04Writev33() throws Exception { |
|
|
|
|
//read();
|
|
|
|
|
//Thread.sleep(10*1000);
|
|
|
|
|
|
|
|
|
|
LOGGER.info("第五次:{}", System.currentTimeMillis() - start); |
|
|
|
|
} |
|
|
|
|
read(); |
|
|
|
|
|
|
|
|
|
private void v2(Cellhanderl cellhanderl1) { |
|
|
|
|
cellhanderl1.beforeCellCreate(null); |
|
|
|
|
cellhanderl1.afterCellCreate(null); |
|
|
|
|
cellhanderl1.afterCellDataConverted(null); |
|
|
|
|
cellhanderl1.afterCellDispose(null); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void read() throws Exception { |
|
|
|
|
long start = System.currentTimeMillis(); |
|
|
|
|
try (FileOutputStream fileOutputStream = new FileOutputStream(fileWritePoi07)) { |
|
|
|
|
SXSSFWorkbook workbook = new SXSSFWorkbook(); |
|
|
|
|
SXSSFSheet sheet = workbook.createSheet("sheet1"); |
|
|
|
|
for (int i = 0; i < 20 * 5000; i++) { |
|
|
|
|
SXSSFRow row = sheet.createRow(i); |
|
|
|
|
for (int j = 0; j < 25; j++) { |
|
|
|
|
SXSSFCell cell = row.createCell(j); |
|
|
|
|
cell.setCellValue("str-" + j + "-" + i); |
|
|
|
|
} |
|
|
|
|
if (i % 5000 == 0) { |
|
|
|
|
//LOGGER.info("{} write success.", i);
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
workbook.write(fileOutputStream); |
|
|
|
|
workbook.dispose(); |
|
|
|
|
workbook.close(); |
|
|
|
|
} |
|
|
|
|
//try (FileOutputStream fileOutputStream = new FileOutputStream(fileWritePoi07)) {
|
|
|
|
|
// SXSSFWorkbook workbook = new SXSSFWorkbook();
|
|
|
|
|
// SXSSFSheet sheet = workbook.createSheet("sheet1");
|
|
|
|
|
// for (int i = 0; i < 20 * 5000; i++) {
|
|
|
|
|
// SXSSFRow row = sheet.createRow(i);
|
|
|
|
|
// for (int j = 0; j < 25; j++) {
|
|
|
|
|
// SXSSFCell cell = row.createCell(j);
|
|
|
|
|
// cell.setCellValue("str-" + j + "-" + i);
|
|
|
|
|
// }
|
|
|
|
|
// if (i % 5000 == 0) {
|
|
|
|
|
// //LOGGER.info("{} write success.", i);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// workbook.write(fileOutputStream);
|
|
|
|
|
// workbook.dispose();
|
|
|
|
|
// workbook.close();
|
|
|
|
|
//}
|
|
|
|
|
long costPoi = System.currentTimeMillis() - start; |
|
|
|
|
LOGGER.info("poi写入消费:{}", System.currentTimeMillis() - start); |
|
|
|
|
|
|
|
|
@ -263,7 +340,7 @@ public class LargeDataTest {
|
|
|
|
|
LOGGER.info("easyxcel写入:{}", CostUtil.count2); |
|
|
|
|
LOGGER.info("easyxcel写入:{}", CostUtil.count); |
|
|
|
|
LOGGER.info("easyxcel写入:{}", FillStyleCellWriteHandler.count); |
|
|
|
|
|
|
|
|
|
LOGGER.info("easyxcel写入:{}", WriteWorkbookHolder.count); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|