mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-31 04:28:51 +00:00
ReferenceHelper Benchmarks
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetPerformance\ReferenceHelper;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
|
||||
abstract class AbstractInsertDelete
|
||||
{
|
||||
/**
|
||||
* @var Spreadsheet
|
||||
*/
|
||||
protected $spreadsheet;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $fileName = 'php://temp';
|
||||
|
||||
public function __construct(int $columns = 32, int $rows = 512)
|
||||
{
|
||||
$this->spreadsheet = new Spreadsheet();
|
||||
|
||||
$worksheet = $this->spreadsheet->getActiveSheet();
|
||||
|
||||
$this->buildWorksheet($worksheet, $rows, $columns);
|
||||
}
|
||||
|
||||
private function buildWorksheet(Worksheet $worksheet, int $rows, int $columns): void
|
||||
{
|
||||
$sampleData = [range(1, $columns)];
|
||||
|
||||
for ($row = 1; $row <= $rows; ++$row) {
|
||||
$worksheet->fromArray($sampleData, null, "A{$row}", true);
|
||||
}
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
if (file_exists($this->fileName)) {
|
||||
unlink($this->fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetPerformance\ReferenceHelper;
|
||||
|
||||
class InsertColumnBenchmark extends AbstractInsertDelete
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(78, 2048);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Groups({"slow"})
|
||||
* @revs(4)
|
||||
* @Iterations(5)
|
||||
* @OutputTimeUnit("seconds")
|
||||
* @AfterMethods("tearDown")
|
||||
*/
|
||||
public function benchmarkInsertColumnsEarly(): void
|
||||
{
|
||||
$this->spreadsheet->getActiveSheet()->insertNewColumnBefore('C', 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Groups({"slow"})
|
||||
* @revs(4)
|
||||
* @Iterations(5)
|
||||
* @OutputTimeUnit("seconds")
|
||||
* @AfterMethods("tearDown")
|
||||
*/
|
||||
public function benchmarkInsertColumnsMid(): void
|
||||
{
|
||||
$this->spreadsheet->getActiveSheet()->insertNewColumnBefore('AB', 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Groups({"slow"})
|
||||
* @revs(4)
|
||||
* @Iterations(7)
|
||||
* @OutputTimeUnit("seconds")
|
||||
* @AfterMethods("tearDown")
|
||||
*/
|
||||
public function benchmarkInsertColumnsLate(): void
|
||||
{
|
||||
$this->spreadsheet->getActiveSheet()->insertNewColumnBefore('BX', 2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetPerformance\ReferenceHelper;
|
||||
|
||||
class InsertRowBenchmark extends AbstractInsertDelete
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(256, 512);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Groups({"slow"})
|
||||
* @revs(4)
|
||||
* @Iterations(5)
|
||||
* @OutputTimeUnit("seconds")
|
||||
* @AfterMethods("tearDown")
|
||||
*/
|
||||
public function benchmarkInsertRowsEarly(): void
|
||||
{
|
||||
$this->spreadsheet->getActiveSheet()->insertNewRowBefore(2, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Groups({"slow"})
|
||||
* @revs(4)
|
||||
* @Iterations(7)
|
||||
* @OutputTimeUnit("seconds")
|
||||
* @AfterMethods("tearDown")
|
||||
*/
|
||||
public function benchmarkInsertRowsMid(): void
|
||||
{
|
||||
$this->spreadsheet->getActiveSheet()->insertNewRowBefore(255, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Groups({"slow"})
|
||||
* @revs(4)
|
||||
* @Iterations(11)
|
||||
* @OutputTimeUnit("seconds")
|
||||
* @AfterMethods("tearDown")
|
||||
*/
|
||||
public function benchmarkInsertRowsLate(): void
|
||||
{
|
||||
$this->spreadsheet->getActiveSheet()->insertNewRowBefore(510, 4);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetPerformance\ReferenceHelper;
|
||||
|
||||
class RemoveColumnBenchmark extends AbstractInsertDelete
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(78, 2048);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Groups({"slow"})
|
||||
* @revs(4)
|
||||
* @Iterations(5)
|
||||
* @OutputTimeUnit("seconds")
|
||||
* @AfterMethods("tearDown")
|
||||
*/
|
||||
public function benchmarkRemoveColumnsEarly(): void
|
||||
{
|
||||
$this->spreadsheet->getActiveSheet()->removeColumn('C', 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Groups({"slow"})
|
||||
* @revs(4)
|
||||
* @Iterations(5)
|
||||
* @OutputTimeUnit("seconds")
|
||||
* @AfterMethods("tearDown")
|
||||
*/
|
||||
public function benchmarkRemoveColumnsMid(): void
|
||||
{
|
||||
$this->spreadsheet->getActiveSheet()->removeColumn('AB', 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Groups({"slow"})
|
||||
* @revs(4)
|
||||
* @Iterations(7)
|
||||
* @OutputTimeUnit("seconds")
|
||||
* @AfterMethods("tearDown")
|
||||
*/
|
||||
public function benchmarkRemoveColumnsLate(): void
|
||||
{
|
||||
$this->spreadsheet->getActiveSheet()->removeColumn('BX', 2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetPerformance\ReferenceHelper;
|
||||
|
||||
class RemoveRowBenchmark extends AbstractInsertDelete
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(256, 512);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Groups({"slow"})
|
||||
* @revs(4)
|
||||
* @Iterations(5)
|
||||
* @OutputTimeUnit("seconds")
|
||||
* @AfterMethods("tearDown")
|
||||
*/
|
||||
public function benchmarkRemoveRowsEarly(): void
|
||||
{
|
||||
$this->spreadsheet->getActiveSheet()->removeRow(2, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Groups({"slow"})
|
||||
* @revs(4)
|
||||
* @Iterations(7)
|
||||
* @OutputTimeUnit("seconds")
|
||||
* @AfterMethods("tearDown")
|
||||
*/
|
||||
public function benchmarkRemoveRowsMid(): void
|
||||
{
|
||||
$this->spreadsheet->getActiveSheet()->removeRow(255, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Groups({"slow"})
|
||||
* @revs(4)
|
||||
* @Iterations(11)
|
||||
* @OutputTimeUnit("seconds")
|
||||
* @AfterMethods("tearDown")
|
||||
*/
|
||||
public function benchmarkRemoveRowsLate(): void
|
||||
{
|
||||
$this->spreadsheet->getActiveSheet()->removeRow(510, 4);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user