-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: svrnm <[email protected]>
- Loading branch information
Showing
8 changed files
with
140 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: Common Setup | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
php-version: | ||
required: true | ||
type: string | ||
cache-key-suffix: | ||
required: true | ||
type: string | ||
|
||
jobs: | ||
setup: | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ inputs.php-version }} | ||
extensions: mbstring, pdo, pdo_mysql | ||
ini-values: | | ||
memory_limit=512M | ||
coverage: none | ||
|
||
- name: Get Composer Cache | ||
id: composer-cache | ||
uses: actions/cache@v4 | ||
with: | ||
path: ~/.composer/cache | ||
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}-${{ inputs.cache-key-suffix }} | ||
restore-keys: ${{ runner.os }}-composer-${{ inputs.cache-key-suffix }} | ||
|
||
- name: Install dependencies | ||
run: composer install --prefer-dist --no-progress --no-suggest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Run PhpBench | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
workflow_dispatch: | ||
|
||
jobs: | ||
phpbench: | ||
runs-on: ubuntu-22.04 | ||
|
||
strategy: | ||
matrix: | ||
php-version: ['7.0', '7.4', '8.0', '8.3'] | ||
|
||
steps: | ||
- name: Common Setup | ||
uses: ./.github/workflows/common.yml | ||
with: | ||
php-version: ${{ matrix.php-version }} | ||
cache-key-suffix: ${{ matrix.php-version }} | ||
|
||
- name: Run PhpBench | ||
run: vendor/bin/phpbench run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
examples/test.xlsx | ||
/vendor | ||
composer.lock | ||
*.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"$schema":"./vendor/phpbench/phpbench/phpbench.schema.json", | ||
"runner.bootstrap": "vendor/autoload.php" | ||
} |
58 changes: 58 additions & 0 deletions
58
tests/Svrnm/ExcelDataTables/Benchmark/AttachToFileBench.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
namespace Svrnm\ExcelDataTables\Benchmark; | ||
|
||
use Svrnm\ExcelDataTables\ExcelDataTable; | ||
|
||
class AttachToFileBench | ||
{ | ||
/** | ||
* @Revs(10) | ||
* @Iterations(2) | ||
* @ParamProviders("provideAttachToFile") | ||
*/ | ||
public function benchAttachToFile(array $params) | ||
{ | ||
$dataTable = new ExcelDataTable(); | ||
$in = __DIR__ . '/../../../../examples/spec.xlsx'; | ||
|
||
// output file need to be recreated => delete if exists | ||
$out = __DIR__ . '/../../../../examples/test.xlsx'; | ||
if( file_exists($out) ) { | ||
if( !@unlink ( $out ) ) | ||
{ | ||
echo "CRITIC! - destination file: $out - has to be deleted, and I can't<br>"; | ||
echo "CRITIC! - check directory and file permissions<br>"; | ||
die(); | ||
} | ||
} | ||
$dataTable->showHeaders()->addRows($params["data"])->attachToFile($in, $out, false); | ||
} | ||
|
||
private static function generate($rows, $cols) { | ||
$data = array(); | ||
for($i = 0; $i < $rows; $i++) { | ||
$row = array(); | ||
for($j = 0; $j < $cols; $j++) { | ||
switch($j%3) { | ||
case 0: | ||
$row[] = $i; | ||
break; | ||
case 1: | ||
$row[] = '('.$i.','.$j.')' ; | ||
break; | ||
case 2: | ||
$row[] = new \DateTime('2024-01-01'); | ||
break; | ||
} | ||
} | ||
$data[] = $row; | ||
} | ||
return $data; | ||
} | ||
|
||
public function provideAttachToFile() { | ||
yield '100x100' => ['data' => self::generate(100, 100)]; | ||
yield '200x200' => ['data' => self::generate(200, 200)]; | ||
yield '400x400' => ['data' => self::generate(400, 400)]; | ||
} | ||
} |