I’m trying to draw a picture using cell background color, I choose beanshell to do this.
After studied how to change CellBackColor from here, I wrote a performance test script, and run it, and the performance is not good, is there a way that I can increase the performance?
Test result
// -----------------------------------------------------------------------------
// Output on a {CPU: AMD Ryzen 5 2400G, Memory: 32GB, OS: Fedora 41, LibreOffice: 25.2.2.2} computer.
// -----------------------------------------------------------------------------
time cost of changing CellBackColor of 10x10 100 cells = 895 ms.
time cost of changing CellBackColor of 10x10 100 cells = 762 ms.
time cost of changing CellBackColor of 10x10 100 cells = 792 ms.
time cost of changing CellBackColor of 10x10 100 cells = 761 ms.
time cost of changing CellBackColor of 10x10 100 cells = 605 ms.
time cost of changing CellBackColor of 10x10 100 cells = 709 ms.
time cost of changing CellBackColor of 10x10 100 cells = 643 ms.
time cost of changing CellBackColor of 10x10 100 cells = 739 ms.
time cost of changing CellBackColor of 50x20 1000 cells = 4132 ms.
time cost of changing CellBackColor of 50x20 1000 cells = 4636 ms.
time cost of changing CellBackColor of 50x20 1000 cells = 4731 ms.
time cost of changing CellBackColor of 50x20 1000 cells = 4885 ms.
time cost of changing CellBackColor of 50x20 1000 cells = 5031 ms.
time cost of changing CellBackColor of 50x20 1000 cells = 4450 ms.
time cost of changing CellBackColor of 50x20 1000 cells = 4609 ms.
time cost of changing CellBackColor of 50x20 1000 cells = 4617 ms.
time cost of changing CellBackColor of 50x20 1000 cells = 4785 ms.
time cost of changing CellBackColor of 50x20 1000 cells = 4886 ms.
time cost of changing CellBackColor of 20x50 1000 cells = 6865 ms.
time cost of changing CellBackColor of 20x50 1000 cells = 7759 ms.
time cost of changing CellBackColor of 20x50 1000 cells = 7692 ms.
time cost of changing CellBackColor of 20x50 1000 cells = 7235 ms.
time cost of changing CellBackColor of 20x50 1000 cells = 7821 ms.
time cost of changing CellBackColor of 20x50 1000 cells = 7282 ms.
time cost of changing CellBackColor of 20x50 1000 cells = 7529 ms.
time cost of changing CellBackColor of 20x50 1000 cells = 7357 ms.
time cost of changing CellBackColor of 20x50 1000 cells = 7168 ms.
time cost of changing CellBackColor of 20x50 1000 cells = 7556 ms.
Test script
import com.sun.star.uno.*;
import com.sun.star.beans.XPropertySet;
import com.sun.star.sheet.*;
import com.sun.star.table.*;
model = XSCRIPTCONTEXT.getDocument ();
controller = model.getCurrentController ();
view = UnoRuntime.queryInterface (XSpreadsheetView.class, controller);
sheet = view.getActiveSheet ();
Thread threadTest = new Thread ()
{
public void run ()
{
try
{
//int nWidth = 10, nHeight = 10;
//int nWidth = 50, nHeight = 20;
int nWidth = 20, nHeight = 50;
long nTimestamp_Start = System.currentTimeMillis ();
for (int iRow=0; iRow<nHeight; iRow++)
{
for (int iCol=0; iCol<nWidth; iCol++)
{
cell = sheet.getCellByPosition (iCol, iRow);
XPropertySet cell_prop_set = UnoRuntime.queryInterface (XPropertySet.class, cell);
int nRGB = Math.random () * 0xFFFFFF;
cell_prop_set.setPropertyValue ("CellBackColor", nRGB);
}
}
long nTimestamp_End = System.currentTimeMillis ();
long nDurationInMillisecond = nTimestamp_End - nTimestamp_Start;
//long nDurationInSecond = nDurationInMillisecond / 1000;
System.out.println ("time cost of changing CellBackColor of " + nWidth + "x" + nHeight + " " + (nWidth*nHeight) + " cells = " + nDurationInMillisecond + " ms.");
// -----------------------------------------------------------------------------
// Output on a {CPU: AMD Ryzen 5 2400G, Memory: 32GB, OS: Fedora 41, LibreOffice: 25.2.2.2} computer.
// -----------------------------------------------------------------------------
//time cost of changing CellBackColor of 10x10 100 cells = 895 ms.
//time cost of changing CellBackColor of 10x10 100 cells = 762 ms.
//time cost of changing CellBackColor of 10x10 100 cells = 792 ms.
//time cost of changing CellBackColor of 10x10 100 cells = 761 ms.
//time cost of changing CellBackColor of 10x10 100 cells = 605 ms.
//time cost of changing CellBackColor of 10x10 100 cells = 709 ms.
//time cost of changing CellBackColor of 10x10 100 cells = 643 ms.
//time cost of changing CellBackColor of 10x10 100 cells = 739 ms.
//
//time cost of changing CellBackColor of 50x20 1000 cells = 4132 ms.
//time cost of changing CellBackColor of 50x20 1000 cells = 4636 ms.
//time cost of changing CellBackColor of 50x20 1000 cells = 4731 ms.
//time cost of changing CellBackColor of 50x20 1000 cells = 4885 ms.
//time cost of changing CellBackColor of 50x20 1000 cells = 5031 ms.
//time cost of changing CellBackColor of 50x20 1000 cells = 4450 ms.
//time cost of changing CellBackColor of 50x20 1000 cells = 4609 ms.
//time cost of changing CellBackColor of 50x20 1000 cells = 4617 ms.
//time cost of changing CellBackColor of 50x20 1000 cells = 4785 ms.
//time cost of changing CellBackColor of 50x20 1000 cells = 4886 ms.
//
//time cost of changing CellBackColor of 20x50 1000 cells = 6865 ms.
//time cost of changing CellBackColor of 20x50 1000 cells = 7759 ms.
//time cost of changing CellBackColor of 20x50 1000 cells = 7692 ms.
//time cost of changing CellBackColor of 20x50 1000 cells = 7235 ms.
//time cost of changing CellBackColor of 20x50 1000 cells = 7821 ms.
//time cost of changing CellBackColor of 20x50 1000 cells = 7282 ms.
//time cost of changing CellBackColor of 20x50 1000 cells = 7529 ms.
//time cost of changing CellBackColor of 20x50 1000 cells = 7357 ms.
//time cost of changing CellBackColor of 20x50 1000 cells = 7168 ms.
//time cost of changing CellBackColor of 20x50 1000 cells = 7556 ms.
}
catch (Exception e)
{
e.printStackTrace ();
}
}
};
try
{
threadTest.start ();
}
catch (Exception e)
{
e.printStackTrace ();
}
return 0;