Skip to content

Add phpbench #352

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

Merged
merged 4 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/tools export-ignore
/tests/benchmarks export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.editorconfig export-ignore
.github export-ignore
.weblate export-ignore
.scrutinizer.yml export-ignore
infection.json.dist export-ignore
phpbench.json export-ignore
phpcs.xml.dist export-ignore
phpstan.neon.dist export-ignore
phpstan-baseline.neon export-ignore
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint-and-analyse-php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use php 7.1
- name: Use php 7.2
uses: shivammathur/setup-php@v2
with:
php-version: 7.1
php-version: 7.2
tools: composer:v2
- name: Validate composer.json and composer.lock
run: composer validate
Expand Down
53 changes: 50 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
continue-on-error: ${{ matrix.experimental }}
strategy:
matrix:
php-version: ["7.1", "7.2", "7.3", "7.4", "8.0", "8.1", "8.2"]
php-version: ["7.2", "7.3", "7.4", "8.0", "8.1", "8.2"]
os: [ubuntu-latest]
experimental: [false]
composer-options: ['']
Expand Down Expand Up @@ -51,8 +51,8 @@ jobs:
- name: Install dependencies
run: composer install --no-interaction ${{ matrix.composer-options }}
- name: Install motranslator
if: ${{ matrix.php-version == '7.1' }}
run: composer require phpmyadmin/motranslator:^3.0
if: ${{ matrix.php-version == '7.2' }}
run: composer require phpmyadmin/motranslator:^3.0 --with-all-dependencies --no-interaction
- name: Run php tests
run: composer run phpunit
- name: Send coverage
Expand All @@ -63,3 +63,50 @@ jobs:
if: github.repository == 'phpmyadmin/sql-parser'
with:
cli-args: "--format=php-clover build/logs/clover.xml --revision=${{ github.event.pull_request.head.sha || github.sha }}"

php-benchmark:
name: Benchmark on PHP ${{ matrix.php-version }} and ${{ matrix.os }}
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.experimental }}
strategy:
matrix:
php-version: ["7.2", "7.3", "7.4", "8.0", "8.1", "8.2"]
os: [ubuntu-latest]
experimental: [false]
composer-options: ['']
include:
- { php-version: 'nightly', experimental: true, os: ubuntu-latest, composer-options: '--ignore-platform-reqs' }
steps:
- uses: actions/checkout@v3
with:
# Fetch some commits for Scrutinizer coverage upload
fetch-depth: 15
- name: Use PHP ${{ matrix.php-version }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
# phar, json and curl are used by composer
# json is used by testing code
# dom, json, mbstring, libxml, xml, xmlwriter are used by phpunit
# tokenizer, xmlwriter and simplexml are used by phpcs
# ctype is used by Psalm
extensions: none, mbstring, phar, json, curl, tokenizer, xml, xmlwriter, simplexml, libxml, dom, ctype
coverage: xdebug
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Restore cache
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install dependencies
run: composer install --no-interaction ${{ matrix.composer-options }}
- name: Install motranslator
if: ${{ matrix.php-version == '7.2' }}
run: composer require phpmyadmin/motranslator:^3.0 --with-all-dependencies --no-interaction
- name: Run benchmarks
run: composer run phpbench
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ build:
nodes:
analysis:
environment:
php: 7.1
php: 7.2
dependencies:
before:
- composer install
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* Performance improvement to use less the `nextToken()` function (#397)
* Lexer - Solving ambiguity on function keywords (#385)
* Drop PHP 7.1 support

## [5.6.0] - 2023-01-02

Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
}
],
"require": {
"php": "^7.1 || ^8.0",
"php": "^7.2 || ^8.0",
"symfony/polyfill-mbstring": "^1.3",
"symfony/polyfill-php80": "^1.16"
},
"require-dev": {
"phpbench/phpbench": "^1.1",
"phpmyadmin/coding-standard": "^3.0",
"phpmyadmin/motranslator": "^4.0 || ^5.0",
"phpstan/extension-installer": "^1.1",
Expand Down Expand Up @@ -66,6 +67,7 @@
"phpstan": "@php phpstan analyse",
"psalm": "@php psalm --no-diff",
"phpunit": "@php phpunit --color=always",
"phpbench": "@php phpbench run tests/benchmarks --report=aggregate --progress=dots",
"test": [
"@phpcs",
"@phpstan",
Expand Down
4 changes: 4 additions & 0 deletions phpbench.json
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"
}
67 changes: 67 additions & 0 deletions tests/benchmarks/UtfStringBench.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

declare(strict_types=1);

namespace PhpMyAdmin\SqlParser\Tests\benchmarks;

use PhpMyAdmin\SqlParser\UtfString;

use function chr;
use function file_get_contents;

class UtfStringBench
{
/** @var string */
private $testContents;

/**
* @BeforeMethods("setUp")
* @Iterations(20)
* @Revs(4)
* @OutputTimeUnit("milliseconds")
* @Assert("mode(variant.time.avg) < 38 milliseconds +/- 10%")
* @Assert("mode(variant.time.avg) > 20 milliseconds +/- 10%")
*/
public function benchBuildUtfString(): void
{
$str1 = new UtfString($this->testContents);
for ($i = 0; $i < $str1->length(); $i++) {
$str1[$i];// Make offset offsetGet work
}
}

/**
* @BeforeMethods("setUp")
* @Iterations(2)
* @Revs(2)
* @OutputTimeUnit("microseconds")
* @Assert("mode(variant.time.avg) < 75 microseconds +/- 10%")
* @Assert("mode(variant.time.avg) > 60 microseconds +/- 10%")
*/
public function benchGetCharLength(): void
{
UtfString::getCharLength(chr(0x00)); // 00000000
UtfString::getCharLength(chr(0x7F)); // 01111111

UtfString::getCharLength(chr(0xC0)); // 11000000
UtfString::getCharLength(chr(0xDF)); // 11011111

UtfString::getCharLength(chr(0xE0)); // 11100000
UtfString::getCharLength(chr(0xEF)); // 11101111

UtfString::getCharLength(chr(0xF0)); // 11110000
UtfString::getCharLength(chr(0xF7)); // 11110111

UtfString::getCharLength(chr(0xF8)); // 11111000
UtfString::getCharLength(chr(0xFB)); // 11111011

UtfString::getCharLength(chr(0xFC)); // 11111100
UtfString::getCharLength(chr(0xFD)); // 11111101
}

public function setUp(): void
{
$contentsPath = __DIR__ . '/../../LICENSE.txt';
$this->testContents = (string) file_get_contents($contentsPath);
}
}