Hello again.
I have some questions about writing performance.
I try to populate a area in my attached excel-file wb.xls. Seen marked with yellow background in the document.
Im getting an average writing speed of about 204 cells per second, with my code.
To read the 23*23 area it takes about 2,5 seconds, its slow.
And when repeating this process (as part of a simulation) it take a whole lot of time.
What in the fillWithArray()-function takes time?
How much overhead is there in performing the function fillWithArray()?
Could I call native functions / use native peers to make it faster?
The million dollar question is: How can I make it to get faster?
Here's the code for the operation:
public class WriteReadTest {
private Workbook workbook;
private Application application;
public WriteReadTest() {
try{
long time1 = System.currentTimeMillis();
long time2 = System.currentTimeMillis();
DecimalFormat df = new DecimalFormat("0.##");
Random rand = new java.util.Random();
ArrayList<Object> dl = new ArrayList<Object>();
time1 = System.currentTimeMillis();
application = new Application();///Makes a new application
File xlsFile = new File("wb.xls");
workbook = application.openWorkbook(xlsFile);
time2 = System.currentTimeMillis();
long sum= (time2-time1);
System.out.println("Started application and opened the wb.xls in " + sum + " ms");
Cell startCell = workbook.getWorksheet(1).getCell(46,2); //startCell in Sheet1
double[][] data = new double[23][23];//A twodim table with random values
double dimension = 23*23; //dimension of table
data = new double[23][23];
for (int i=0;i<23;i++){
for (int j=0;j<23;j++){
data+[j] = rand.nextInt(10);
}
}
Worksheet w = workbook.getWorksheet(1);
time1 = System.currentTimeMillis();
w.fillWithArray(startCell, data); //#### Fills with array.
time2 = System.currentTimeMillis();
sum= (time2-time1);
double sek = (sum/1000.00);
System.out.println(sek);
System.out.println("Writing filling range 'B46:X68' took " + sum + " ms. Writingspeed per cell : " + df.format(dimension/(sum/1000.00)) + " cells per second");
workbook.saveCopyAs(new File("data/wb_runned.xls"));//Optionally, to see what numbers got inserted
workbook.close(false);
application.close();
} catch (FileNotFoundException ex) {
ex.printStackTrace();
workbook.close(false);
application.close();
} catch (ExcelException ex) {
ex.printStackTrace();
workbook.close(false);
application.close();
}catch (IOException ex) {
ex.printStackTrace();
}
}
public static void main(String[] args) {
WriteReadTest wrt = new WriteReadTest();
}
Message was edited by: att
Attachments:
- wb.xls (101.5 K)