Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check $strictNullComparison outside of loops #3347

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ConnectGrid
Copy link

Might be considered a micro-optimization, but for large sheets, it could make a difference in performance. Only check the $strictNullComparison condition once, not for every single cell loop.

This is:

  • a bugfix
  • a new feature
  • refactoring
  • additional unit tests

Checklist:

  • Changes are covered by unit tests
    • Changes are covered by existing unit tests
    • New unit tests have been added
  • Code style is respected
  • Commit message explains why the change is made (see https://github.com/erlang/otp/wiki/Writing-good-commit-messages)
  • CHANGELOG.md contains a short summary of the change and a link to the pull request if applicable
  • Documentation is updated as necessary

Why this change is needed?

Instantiating Worksheets from an array are currently less than optimal due to checking a boolean condition on every single cell loop.

if ($strictNullComparison) {
foreach ($source as $rowData) {
$currentColumn = $startColumn;
foreach ($rowData as $cellValue) {
if ($cellValue !== $nullValue) {
// Set cell value
$this->getCell($currentColumn . $startRow)->setValue($cellValue);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've not run any timing tests on your code yet; but when it comes to micro-optimisations, then interpolation is more efficient than the concatenation that we use here:

$this->getCell("{$currentColumn}{$startRow}")->setValue($cellValue);

Try running

$callStartTime = microtime(true);

for ($row = 1; $row <= 65535; ++$row) {
    for ($column = 'A'; $column !== 'IV'; ++$column) {
        $cellAddress = $column . $row;
    }
}

$callEndTime = microtime(true);
$concatenationCallTime = $callEndTime - $callStartTime;

echo PHP_EOL;
echo 'Call time for concatenation was ' , sprintf('%.4f', $concatenationCallTime) , ' seconds' , PHP_EOL;


$callStartTime = microtime(true);

for ($row = 1; $row <= 65535; ++$row) {
    for ($column = 'A'; $column !== 'IV'; ++$column) {
        $cellAddress = "{$column}{$row}";
    }
}

$callEndTime = microtime(true);
$interpolationCallTime = $callEndTime - $callStartTime;

echo PHP_EOL;
echo 'Call time for interpolation was ' , sprintf('%.4f', $interpolationCallTime) , ' seconds' , PHP_EOL;

to see the difference

And I'm of the growing opinion that interpolation is actually more readable

Might be considered a micro-optimization, but for large sheets, it could make a difference in performance. Only check the `$strictNullComparison` condition once, not for every single cell loop.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants