Skip to content

Commit 4606163

Browse files
author
MarkBaker
committed
ReferenceHelper Benchmarks
1 parent a9375b6 commit 4606163

File tree

5 files changed

+232
-0
lines changed

5 files changed

+232
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace PhpOffice\PhpSpreadsheetPerformance\ReferenceHelper;
4+
5+
use PhpOffice\PhpSpreadsheet\Spreadsheet;
6+
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
7+
8+
abstract class AbstractInsertDelete
9+
{
10+
/**
11+
* @var Spreadsheet
12+
*/
13+
protected $spreadsheet;
14+
15+
/**
16+
* @var string
17+
*/
18+
protected $fileName = 'php://temp';
19+
20+
public function __construct(int $columns = 32, int $rows = 512)
21+
{
22+
$this->spreadsheet = new Spreadsheet();
23+
24+
$worksheet = $this->spreadsheet->getActiveSheet();
25+
26+
$this->buildWorksheet($worksheet, $rows, $columns);
27+
}
28+
29+
private function buildWorksheet(Worksheet $worksheet, int $rows, int $columns): void
30+
{
31+
$sampleData = [range(1, $columns)];
32+
33+
for ($row = 1; $row <= $rows; ++$row) {
34+
$worksheet->fromArray($sampleData, null, "A{$row}", true);
35+
}
36+
}
37+
38+
public function tearDown(): void
39+
{
40+
if (file_exists($this->fileName)) {
41+
unlink($this->fileName);
42+
}
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace PhpOffice\PhpSpreadsheetPerformance\ReferenceHelper;
4+
5+
class InsertColumnBenchmark extends AbstractInsertDelete
6+
{
7+
public function __construct()
8+
{
9+
parent::__construct(78, 2048);
10+
}
11+
12+
/**
13+
* @Groups({"slow"})
14+
* @revs(4)
15+
* @Iterations(5)
16+
* @OutputTimeUnit("seconds")
17+
* @AfterMethods("tearDown")
18+
*/
19+
public function benchmarkInsertColumnsEarly(): void
20+
{
21+
$this->spreadsheet->getActiveSheet()->insertNewColumnBefore('C', 2);
22+
}
23+
24+
/**
25+
* @Groups({"slow"})
26+
* @revs(4)
27+
* @Iterations(5)
28+
* @OutputTimeUnit("seconds")
29+
* @AfterMethods("tearDown")
30+
*/
31+
public function benchmarkInsertColumnsMid(): void
32+
{
33+
$this->spreadsheet->getActiveSheet()->insertNewColumnBefore('AB', 2);
34+
}
35+
36+
/**
37+
* @Groups({"slow"})
38+
* @revs(4)
39+
* @Iterations(7)
40+
* @OutputTimeUnit("seconds")
41+
* @AfterMethods("tearDown")
42+
*/
43+
public function benchmarkInsertColumnsLate(): void
44+
{
45+
$this->spreadsheet->getActiveSheet()->insertNewColumnBefore('BX', 2);
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace PhpOffice\PhpSpreadsheetPerformance\ReferenceHelper;
4+
5+
class InsertRowBenchmark extends AbstractInsertDelete
6+
{
7+
public function __construct()
8+
{
9+
parent::__construct(256, 512);
10+
}
11+
12+
/**
13+
* @Groups({"slow"})
14+
* @revs(4)
15+
* @Iterations(5)
16+
* @OutputTimeUnit("seconds")
17+
* @AfterMethods("tearDown")
18+
*/
19+
public function benchmarkInsertRowsEarly(): void
20+
{
21+
$this->spreadsheet->getActiveSheet()->insertNewRowBefore(2, 4);
22+
}
23+
24+
/**
25+
* @Groups({"slow"})
26+
* @revs(4)
27+
* @Iterations(7)
28+
* @OutputTimeUnit("seconds")
29+
* @AfterMethods("tearDown")
30+
*/
31+
public function benchmarkInsertRowsMid(): void
32+
{
33+
$this->spreadsheet->getActiveSheet()->insertNewRowBefore(255, 4);
34+
}
35+
36+
/**
37+
* @Groups({"slow"})
38+
* @revs(4)
39+
* @Iterations(11)
40+
* @OutputTimeUnit("seconds")
41+
* @AfterMethods("tearDown")
42+
*/
43+
public function benchmarkInsertRowsLate(): void
44+
{
45+
$this->spreadsheet->getActiveSheet()->insertNewRowBefore(510, 4);
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace PhpOffice\PhpSpreadsheetPerformance\ReferenceHelper;
4+
5+
class RemoveColumnBenchmark extends AbstractInsertDelete
6+
{
7+
public function __construct()
8+
{
9+
parent::__construct(78, 2048);
10+
}
11+
12+
/**
13+
* @Groups({"slow"})
14+
* @revs(4)
15+
* @Iterations(5)
16+
* @OutputTimeUnit("seconds")
17+
* @AfterMethods("tearDown")
18+
*/
19+
public function benchmarkRemoveColumnsEarly(): void
20+
{
21+
$this->spreadsheet->getActiveSheet()->removeColumn('C', 2);
22+
}
23+
24+
/**
25+
* @Groups({"slow"})
26+
* @revs(4)
27+
* @Iterations(5)
28+
* @OutputTimeUnit("seconds")
29+
* @AfterMethods("tearDown")
30+
*/
31+
public function benchmarkRemoveColumnsMid(): void
32+
{
33+
$this->spreadsheet->getActiveSheet()->removeColumn('AB', 2);
34+
}
35+
36+
/**
37+
* @Groups({"slow"})
38+
* @revs(4)
39+
* @Iterations(7)
40+
* @OutputTimeUnit("seconds")
41+
* @AfterMethods("tearDown")
42+
*/
43+
public function benchmarkRemoveColumnsLate(): void
44+
{
45+
$this->spreadsheet->getActiveSheet()->removeColumn('BX', 2);
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace PhpOffice\PhpSpreadsheetPerformance\ReferenceHelper;
4+
5+
class RemoveRowBenchmark extends AbstractInsertDelete
6+
{
7+
public function __construct()
8+
{
9+
parent::__construct(256, 512);
10+
}
11+
12+
/**
13+
* @Groups({"slow"})
14+
* @revs(4)
15+
* @Iterations(5)
16+
* @OutputTimeUnit("seconds")
17+
* @AfterMethods("tearDown")
18+
*/
19+
public function benchmarkRemoveRowsEarly(): void
20+
{
21+
$this->spreadsheet->getActiveSheet()->removeRow(2, 4);
22+
}
23+
24+
/**
25+
* @Groups({"slow"})
26+
* @revs(4)
27+
* @Iterations(7)
28+
* @OutputTimeUnit("seconds")
29+
* @AfterMethods("tearDown")
30+
*/
31+
public function benchmarkRemoveRowsMid(): void
32+
{
33+
$this->spreadsheet->getActiveSheet()->removeRow(255, 4);
34+
}
35+
36+
/**
37+
* @Groups({"slow"})
38+
* @revs(4)
39+
* @Iterations(11)
40+
* @OutputTimeUnit("seconds")
41+
* @AfterMethods("tearDown")
42+
*/
43+
public function benchmarkRemoveRowsLate(): void
44+
{
45+
$this->spreadsheet->getActiveSheet()->removeRow(510, 4);
46+
}
47+
}

0 commit comments

Comments
 (0)