net.sf.jxls.sample.StressTest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jxls-examples Show documentation
Show all versions of jxls-examples Show documentation
jXLS Examples demonstrate usage of jXLS library
The newest version!
package net.sf.jxls.sample;
import net.sf.jxls.sample.model.Department;
import net.sf.jxls.sample.model.Employee;
import net.sf.jxls.transformer.XLSTransformer;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Workbook;
import java.io.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author Leonid Vysochyn
*/
public class StressTest {
private static String templateFileDir;
private static String destFileDir;
public static void main(String[] args) throws IOException, InvalidFormatException {
if (args.length >= 2) {
templateFileDir = args[0];
destFileDir = args[1];
}
StressTest test = new StressTest();
test.testStress1();
test.testStress2();
}
public void testStress1() throws InvalidFormatException, IOException {
Map beans = new HashMap();
final int employeeCount = 30000;
List employees = Employee.generate(employeeCount);
beans.put("employees", employees);
InputStream is = new BufferedInputStream(new FileInputStream(templateFileDir + "stress1.xls"));
XLSTransformer transformer = new XLSTransformer();
long startTime = System.nanoTime();
Workbook resultWorkbook = transformer.transformXLS(is, beans);
long endTime = System.nanoTime();
is.close();
saveWorkbook(resultWorkbook, destFileDir + "stress1_output.xls");
System.out.println("Stress1 time (s): " + (endTime - startTime)/1000000000);
}
public void testStress2() throws InvalidFormatException, IOException {
Map beans = new HashMap();
final int employeeCount = 500;
final int depCount = 100;
List departments = Department.generate(depCount, employeeCount);
beans.put("departments", departments);
InputStream is = new BufferedInputStream(new FileInputStream(templateFileDir + "stress2.xls"));
XLSTransformer transformer = new XLSTransformer();
long startTime = System.nanoTime();
Workbook resultWorkbook = transformer.transformXLS(is, beans);
long endTime = System.nanoTime();
is.close();
saveWorkbook(resultWorkbook, destFileDir + "stress2_output.xls");
System.out.println("Stress2 time (s): " + (endTime - startTime)/1000000000);
}
private void saveWorkbook(Workbook resultWorkbook, String fileName) throws IOException {
OutputStream os = new BufferedOutputStream(new FileOutputStream(fileName));
resultWorkbook.write(os);
os.flush();
os.close();
}
}