Skip to content

Commit e6320e9

Browse files
committed
Merge #352 - Add phpbench and drop PHP 7.1
Pull-request: #352 Signed-off-by: William Desportes <[email protected]>
2 parents b86a801 + b163fc1 commit e6320e9

File tree

8 files changed

+130
-7
lines changed

8 files changed

+130
-7
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
/tools export-ignore
2+
/tests/benchmarks export-ignore
23
.gitattributes export-ignore
34
.gitignore export-ignore
45
.editorconfig export-ignore
56
.github export-ignore
67
.weblate export-ignore
78
.scrutinizer.yml export-ignore
89
infection.json.dist export-ignore
10+
phpbench.json export-ignore
911
phpcs.xml.dist export-ignore
1012
phpstan.neon.dist export-ignore
1113
phpstan-baseline.neon export-ignore

.github/workflows/lint-and-analyse-php.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ jobs:
1313
runs-on: ubuntu-latest
1414
steps:
1515
- uses: actions/checkout@v3
16-
- name: Use php 7.1
16+
- name: Use php 7.2
1717
uses: shivammathur/setup-php@v2
1818
with:
19-
php-version: 7.1
19+
php-version: 7.2
2020
tools: composer:v2
2121
- name: Validate composer.json and composer.lock
2222
run: composer validate

.github/workflows/tests.yml

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
continue-on-error: ${{ matrix.experimental }}
1616
strategy:
1717
matrix:
18-
php-version: ["7.1", "7.2", "7.3", "7.4", "8.0", "8.1", "8.2"]
18+
php-version: ["7.2", "7.3", "7.4", "8.0", "8.1", "8.2"]
1919
os: [ubuntu-latest]
2020
experimental: [false]
2121
composer-options: ['']
@@ -51,8 +51,8 @@ jobs:
5151
- name: Install dependencies
5252
run: composer install --no-interaction ${{ matrix.composer-options }}
5353
- name: Install motranslator
54-
if: ${{ matrix.php-version == '7.1' }}
55-
run: composer require phpmyadmin/motranslator:^3.0
54+
if: ${{ matrix.php-version == '7.2' }}
55+
run: composer require phpmyadmin/motranslator:^3.0 --with-all-dependencies --no-interaction
5656
- name: Run php tests
5757
run: composer run phpunit
5858
- name: Send coverage
@@ -63,3 +63,50 @@ jobs:
6363
if: github.repository == 'phpmyadmin/sql-parser'
6464
with:
6565
cli-args: "--format=php-clover build/logs/clover.xml --revision=${{ github.event.pull_request.head.sha || github.sha }}"
66+
67+
php-benchmark:
68+
name: Benchmark on PHP ${{ matrix.php-version }} and ${{ matrix.os }}
69+
runs-on: ${{ matrix.os }}
70+
continue-on-error: ${{ matrix.experimental }}
71+
strategy:
72+
matrix:
73+
php-version: ["7.2", "7.3", "7.4", "8.0", "8.1", "8.2"]
74+
os: [ubuntu-latest]
75+
experimental: [false]
76+
composer-options: ['']
77+
include:
78+
- { php-version: 'nightly', experimental: true, os: ubuntu-latest, composer-options: '--ignore-platform-reqs' }
79+
steps:
80+
- uses: actions/checkout@v3
81+
with:
82+
# Fetch some commits for Scrutinizer coverage upload
83+
fetch-depth: 15
84+
- name: Use PHP ${{ matrix.php-version }}
85+
uses: shivammathur/setup-php@v2
86+
with:
87+
php-version: ${{ matrix.php-version }}
88+
# phar, json and curl are used by composer
89+
# json is used by testing code
90+
# dom, json, mbstring, libxml, xml, xmlwriter are used by phpunit
91+
# tokenizer, xmlwriter and simplexml are used by phpcs
92+
# ctype is used by Psalm
93+
extensions: none, mbstring, phar, json, curl, tokenizer, xml, xmlwriter, simplexml, libxml, dom, ctype
94+
coverage: xdebug
95+
- name: Get Composer Cache Directory
96+
id: composer-cache
97+
run: |
98+
echo "::set-output name=dir::$(composer config cache-files-dir)"
99+
- name: Restore cache
100+
uses: actions/cache@v3
101+
with:
102+
path: ${{ steps.composer-cache.outputs.dir }}
103+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
104+
restore-keys: |
105+
${{ runner.os }}-composer-
106+
- name: Install dependencies
107+
run: composer install --no-interaction ${{ matrix.composer-options }}
108+
- name: Install motranslator
109+
if: ${{ matrix.php-version == '7.2' }}
110+
run: composer require phpmyadmin/motranslator:^3.0 --with-all-dependencies --no-interaction
111+
- name: Run benchmarks
112+
run: composer run phpbench

.scrutinizer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ build:
1717
nodes:
1818
analysis:
1919
environment:
20-
php: 7.1
20+
php: 7.2
2121
dependencies:
2222
before:
2323
- composer install

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Lexer - Solving ambiguity on function keywords (#385)
77
* Implement `ALTER EVENT` (#404)
88
* Add `ALTER EVENT` keywords (#404)
9+
* Drop PHP 7.1 support
910

1011
## [5.6.0] - 2023-01-02
1112

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222
}
2323
],
2424
"require": {
25-
"php": "^7.1 || ^8.0",
25+
"php": "^7.2 || ^8.0",
2626
"symfony/polyfill-mbstring": "^1.3",
2727
"symfony/polyfill-php80": "^1.16"
2828
},
2929
"require-dev": {
30+
"phpbench/phpbench": "^1.1",
3031
"phpmyadmin/coding-standard": "^3.0",
3132
"phpmyadmin/motranslator": "^4.0 || ^5.0",
3233
"phpstan/extension-installer": "^1.1",
@@ -66,6 +67,7 @@
6667
"phpstan": "@php phpstan analyse",
6768
"psalm": "@php psalm --no-diff",
6869
"phpunit": "@php phpunit --color=always",
70+
"phpbench": "@php phpbench run tests/benchmarks --report=aggregate --progress=dots",
6971
"test": [
7072
"@phpcs",
7173
"@phpstan",

phpbench.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"$schema": "./vendor/phpbench/phpbench/phpbench.schema.json",
3+
"runner.bootstrap": "vendor/autoload.php"
4+
}

tests/benchmarks/UtfStringBench.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpMyAdmin\SqlParser\Tests\benchmarks;
6+
7+
use PhpMyAdmin\SqlParser\UtfString;
8+
9+
use function chr;
10+
use function file_get_contents;
11+
12+
class UtfStringBench
13+
{
14+
/** @var string */
15+
private $testContents;
16+
17+
/**
18+
* @BeforeMethods("setUp")
19+
* @Iterations(20)
20+
* @Revs(4)
21+
* @OutputTimeUnit("milliseconds")
22+
* @Assert("mode(variant.time.avg) < 38 milliseconds +/- 10%")
23+
* @Assert("mode(variant.time.avg) > 20 milliseconds +/- 10%")
24+
*/
25+
public function benchBuildUtfString(): void
26+
{
27+
$str1 = new UtfString($this->testContents);
28+
for ($i = 0; $i < $str1->length(); $i++) {
29+
$str1[$i];// Make offset offsetGet work
30+
}
31+
}
32+
33+
/**
34+
* @BeforeMethods("setUp")
35+
* @Iterations(2)
36+
* @Revs(2)
37+
* @OutputTimeUnit("microseconds")
38+
* @Assert("mode(variant.time.avg) < 75 microseconds +/- 10%")
39+
* @Assert("mode(variant.time.avg) > 60 microseconds +/- 10%")
40+
*/
41+
public function benchGetCharLength(): void
42+
{
43+
UtfString::getCharLength(chr(0x00)); // 00000000
44+
UtfString::getCharLength(chr(0x7F)); // 01111111
45+
46+
UtfString::getCharLength(chr(0xC0)); // 11000000
47+
UtfString::getCharLength(chr(0xDF)); // 11011111
48+
49+
UtfString::getCharLength(chr(0xE0)); // 11100000
50+
UtfString::getCharLength(chr(0xEF)); // 11101111
51+
52+
UtfString::getCharLength(chr(0xF0)); // 11110000
53+
UtfString::getCharLength(chr(0xF7)); // 11110111
54+
55+
UtfString::getCharLength(chr(0xF8)); // 11111000
56+
UtfString::getCharLength(chr(0xFB)); // 11111011
57+
58+
UtfString::getCharLength(chr(0xFC)); // 11111100
59+
UtfString::getCharLength(chr(0xFD)); // 11111101
60+
}
61+
62+
public function setUp(): void
63+
{
64+
$contentsPath = __DIR__ . '/../../LICENSE.txt';
65+
$this->testContents = (string) file_get_contents($contentsPath);
66+
}
67+
}

0 commit comments

Comments
 (0)