From 439334bc3eb0df09a32bf99b7d02db1656b1499b Mon Sep 17 00:00:00 2001 From: Mika Tuupola Date: Sun, 11 Jan 2026 18:29:27 +0200 Subject: [PATCH 1/2] Upgrade to phpbench/phpbench:^1.4 --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 1befed7..7a8c830 100644 --- a/composer.json +++ b/composer.json @@ -30,8 +30,8 @@ "require-dev": { "squizlabs/php_codesniffer": "^3.0", "phpunit/phpunit": "^7.0|^8.0|^9.0", - "phpbench/phpbench": "^0.15.0|1.0.0-alpha3", - "overtrue/phplint": "^2.3", + "phpbench/phpbench": "^1.4", + "overtrue/phplint": "^9.1", "phpstan/phpstan": "^1.12" }, "suggest": { From 186eaeda1504daef0954f4be3436870670170337 Mon Sep 17 00:00:00 2001 From: Mika Tuupola Date: Sun, 11 Jan 2026 18:30:06 +0200 Subject: [PATCH 2/2] Fix benchmarks to work with new version --- Makefile | 3 ++- README.md | 40 ++++++++++++++++++--------------- benchmarks/Base62Bench.php | 45 ++++++++++++++++++++++++++++++++++++-- phpbench.json | 13 ++++++----- 4 files changed, 74 insertions(+), 27 deletions(-) diff --git a/Makefile b/Makefile index d0b104f..9710078 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,8 @@ static: vendor vendor/bin/phpstan analyse src --level max bench: vendor - vendor/bin/phpbench run benchmarks/ --report=default + vendor/bin/phpbench run benchmarks/ --report=short --group=encoder + vendor/bin/phpbench run benchmarks/ --report=short --group=decoder watch: vendor find . -name "*.php" -not -path "./vendor/*" -o -name "*.json" -not -path "./vendor/*" | entr -c make test diff --git a/README.md b/README.md index 0fd8f5d..f8f1a81 100644 --- a/README.md +++ b/README.md @@ -70,27 +70,31 @@ Install GMP if you can. It is much faster pure PHP encoder. Below benchmarks are ``` $ php --version -PHP 8.0.7 (cli) (built: Jun 4 2021 03:50:01) ( NTS ) +PHP 8.3.20 (cli) (built: Apr 8 2025 20:21:18) (NTS gcc x86_64) $ make bench -+-----------------------+------------------+-----------+ -| subject | mean | diff | -+-----------------------+------------------+-----------+ -| benchGmpDecoder | 140,409.997ops/s | 1.10x | -| benchGmpDecoderCustom | 154,607.297ops/s | 1.00x | -| benchPhpDecoder | 721.147ops/s | 214.39x | -| benchBcmathDecoder | 72.191ops/s | 2,141.64x | -+-----------------------+------------------+-----------+ - -+-----------------------+------------------+-----------+ -| subject | mean | diff | -+-----------------------+------------------+-----------+ -| benchGmpEncoder | 352,609.309ops/s | 1.00x | -| benchGmpEncoderCustom | 350,140.056ops/s | 1.01x | -| benchPhpEncoder | 669.959ops/s | 526.31x | -| benchBcmathEncoder | 72.956ops/s | 4,833.21x | -+-----------------------+------------------+-----------+ ++--------------------------+------------------+ +| subject | mode | ++--------------------------+------------------+ +| benchGmpEncoder | 974,372.664ops/s | +| benchGmpEncoderCustom | 887,630.496ops/s | +| benchPhpEncoder | 1,993.159ops/s | +| benchPhpEncoderCustom | 1,978.154ops/s | +| benchBcmathEncoder | 155.390ops/s | +| benchBcmathEncoderCustom | 155.303ops/s | ++--------------------------+------------------+ + ++--------------------------+------------------+ +| subject | mode | ++--------------------------+------------------+ +| benchGmpDecoder | 289,200.539ops/s | +| benchGmpDecoderCustom | 278,208.793ops/s | +| benchPhpDecoder | 2,030.965ops/s | +| benchPhpDecoderCustom | 2,070.158ops/s | +| benchBcmathDecoder | 148.407ops/s | +| benchBcmathDecoderCustom | 148.725ops/s | ++--------------------------+------------------+ ``` ## Static Proxy diff --git a/benchmarks/Base62Bench.php b/benchmarks/Base62Bench.php index fbb6af9..717eac6 100644 --- a/benchmarks/Base62Bench.php +++ b/benchmarks/Base62Bench.php @@ -3,7 +3,7 @@ /* * This file is part of the Base62 package * - * Copyright (c) 2016-2021 Mika Tuupola + * Copyright (c) 2016-2026 Mika Tuupola * * Licensed under the MIT license: * http://www.opensource.org/licenses/mit-license.php @@ -30,17 +30,22 @@ class Base62Bench { private $data; private $gmp; + private $gmp2; private $php; + private $php2; private $bcmath; + private $bcmath2; private $encoded; public function init() { $this->data = random_bytes(128); $this->gmp = new GmpEncoder; - $this->gmp2 = new GmpEncoder(["characters" => Base62::INVERTED]); + $this->gmp2 = new GmpEncoder(Base62::INVERTED); $this->php = new PhpEncoder; + $this->php2 = new PhpEncoder(Base62::INVERTED); $this->bcmath = new BcmathEncoder; + $this->bcmath2 = new BcmathEncoder(Base62::INVERTED); $this->encoded = $this->php->encode($this->data); } @@ -71,6 +76,15 @@ public function benchPhpEncoder() $encoded = $this->php->encode($this->data); } + /** + * @Revs(100) + * @Groups({"encoder"}) + */ + public function benchPhpEncoderCustom() + { + $encoded = $this->php2->encode($this->data); + } + /** * @Revs(100) * @Groups({"encoder"}) @@ -80,6 +94,15 @@ public function benchBcmathEncoder() $encoded = $this->bcmath->encode($this->data); } + /** + * @Revs(100) + * @Groups({"encoder"}) + */ + public function benchBcmathEncoderCustom() + { + $encoded = $this->bcmath2->encode($this->data); + } + /** * @Revs(100) * @Groups({"decoder"}) @@ -107,6 +130,15 @@ public function benchPhpDecoder() $encoded = $this->php->decode($this->encoded); } + /** + * @Revs(100) + * @Groups({"decoder"}) + */ + public function benchPhpDecoderCustom() + { + $encoded = $this->php2->decode($this->encoded); + } + /** * @Revs(100) * @Groups({"decoder"}) @@ -115,4 +147,13 @@ public function benchBcmathDecoder() { $encoded = $this->bcmath->decode($this->encoded); } + + /** + * @Revs(100) + * @Groups({"decoder"}) + */ + public function benchBcmathDecoderCustom() + { + $encoded = $this->bcmath2->decode($this->encoded); + } } \ No newline at end of file diff --git a/phpbench.json b/phpbench.json index 818ace5..1399d5c 100644 --- a/phpbench.json +++ b/phpbench.json @@ -1,10 +1,11 @@ { - "bootstrap": "vendor/autoload.php", - "reports": { - "default": { - "generator": "table", - "cols": [ "subject", "mean", "diff" ], - "break": ["groups"] + "$schema": "./vendor/phpbench/phpbench/phpbench.schema.json", + "runner.bootstrap": "vendor/autoload.php", + "runner.path": "benchmarks", + "report.generators": { + "short": { + "extends": "aggregate", + "cols": ["subject", "mode"] } } }