Skip to content

About

Benchmarks of PHP ORMs on the same scenarios, against hand-written PDO

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

1 watching

Forks

TESTO

PHP ORM benchmarks

Documentation Support on Boosty

Latest release Verify Security License


The same scenarios on Cycle ORM (as a data mapper with PromiseMapper and as ActiveRecord), Doctrine ORM, Eloquent and Yii ActiveRecord, each measured against hand-written PDO code doing the same work, on SQLite, PostgreSQL and MySQL.

Results

The tables below are written by the Benchmarks workflow on a GitHub-hosted runner (ubuntu-24.04). Each release of this repository carries the results of the ORM versions it ships:

  1. Renovate opens a deps: PR for every new release of an ORM under test, and Verify checks that every contender still does the same work as PDO.
  2. Once merged, release-please opens or updates the release PR, and the benchmarks run on its branch and commit these tables into it, along with results.json: the same numbers with the metadata of the run, in the format of schema/results.schema.json.
  3. Merging the release PR publishes the release with its changelog and its results. Publish attaches results.json to the release and sends it to the Testo site, which keeps every published run. It opens a PR there, or pushes directly when the repository variable DOCS_PUBLISH_MODE is push.

SQLite (in memory)

PHP 8.5.13, SQLite 3.45.1, Linux 7.0.0-1020-azure, 2026-12-02. Each cell: time relative to hand-written PDO (lower is better), then the time per operation and its relative standard deviation. PDO runs alongside every contender on the same runner; the PDO column is the median of those runs.

Scenario PDO Cycle DataMapper 2.19.1 Cycle ActiveRecord 1.2.1 Doctrine ORM 3.8.0 Eloquent 13.45.0 Yii ActiveRecord 1.1.0
Find by primary key 3.8 µs 23.8× · 89.9 µs ±1% 29.9× · 113 µs ±3% 33.3× · 126 µs ±1% 47.1× · 178 µs ±1% 26.5× · 100 µs ±1%
List of 10 rows 18.4 µs 10.4× · 191 µs ±4% 12.7× · 233 µs ±2% 14.6× · 267 µs ±2% 15.7× · 288 µs ±3% 9.7× · 178 µs ±3%
List of 100 rows 151 µs 6.0× · 913 µs ±4% 7.0× · 1.06 ms ±3% 7.7× · 1.16 ms ±6% 7.9× · 1.19 ms ±3% 4.7× · 713 µs ±2%
List of 1000 rows 1.49 ms 4.5× · 6.71 ms ±3% 5.2× · 7.71 ms ±2% 5.9× · 8.74 ms ±3% 4.5× · 6.62 ms ±5% 2.8× · 4.15 ms ±2%
100 rows fetched again 151 µs 3.7× · 564 µs ±5% 3.6× · 547 µs ±3% 5.2× · 782 µs ±4% 7.9× · 1.20 ms ±1% 4.7× · 711 µs ±4%
100 rows as arrays 47.9 µs 9.0× · 433 µs ±4% 10.1× · 486 µs ±3% 12.2× · 583 µs ±5% 8.6× · 412 µs ±6% 13.0× · 622 µs ±5%
Eager belongs-to, 100 posts 225 µs 9.7× · 2.18 ms ±4% 10.5× · 2.37 ms ±6% 7.5× · 1.70 ms ±3% 12.4× · 2.80 ms ±3% 5.8× · 1.30 ms ±4%
Eager has-many, 20 users 457 µs 5.8× · 2.66 ms ±1% 6.2× · 2.86 ms ±4% 6.3× · 2.87 ms ±1% 7.2× · 3.28 ms ±1% 3.9× · 1.77 ms ±5%
Lazy belongs-to, 100 posts 220 µs 9.0× · 1.97 ms ±2% 9.9× · 2.19 ms ±4% 11.6× · 2.55 ms ±3% 63.2× · 13.92 ms ±1% 29.0× · 6.39 ms ±2%
All 10 000 posts 16.24 ms 4.9× · 79.87 ms ±9% 5.5× · 89.96 ms ±3% 5.7× · 92.78 ms ±3% 4.3× · 69.26 ms ±2% 2.8× · 44.69 ms ±4%
Insert 100 users 396 µs 14.5× · 5.74 ms ±3% 31.5× · 12.44 ms ±2% 9.9× · 3.90 ms ±3% 36.1× · 14.29 ms ±3% 16.3× · 6.45 ms ±3%
Insert 20 users + 100 posts 558 µs 12.9× · 7.18 ms ±2% 17.9× · 9.98 ms ±2% 8.6× · 4.79 ms ±10% 33.5× · 18.70 ms ±1% 14.2× · 7.89 ms ±2%
Update 100 users 299 µs 22.2× · 6.64 ms ±5% 42.8× · 12.81 ms ±2% 11.5× · 3.43 ms ±3% 46.5× · 13.90 ms ±3% 14.1× · 4.22 ms ±3%
Delete 100 posts 306 µs 15.0× · 4.59 ms ±3% 32.6× · 9.97 ms ±2% 11.4× · 3.50 ms ±2% 24.2× · 7.41 ms ±4% 8.3× · 2.54 ms ±5%

Peak memory of the process loading all 10 000 posts:

PDO Cycle DataMapper Cycle ActiveRecord Doctrine ORM Eloquent Yii ActiveRecord
13.6 MiB 36.7 MiB 40.2 MiB 22.1 MiB 21.9 MiB 18.7 MiB

PostgreSQL

PHP 8.5.13, PostgreSQL 18.7 (Debian 18.7-1.pgdg13+5), Linux 7.0.0-1020-azure, 2026-12-02. Each cell: time relative to hand-written PDO (lower is better), then the time per operation and its relative standard deviation. PDO runs alongside every contender on the same runner; the PDO column is the median of those runs.

Scenario PDO Cycle DataMapper 2.19.1 Cycle ActiveRecord 1.2.1 Doctrine ORM 3.8.0 Eloquent 13.45.0 Yii ActiveRecord 1.1.0
Find by primary key 150 µs 1.8× · 277 µs ±3% 1.9× · 291 µs ±2% 2.3× · 351 µs ±3% 4.4× · 655 µs ±1% 3.7× · 553 µs ±2%
List of 10 rows 207 µs 2.1× · 434 µs ±2% 2.2× · 462 µs ±14% 2.5× · 507 µs ±1% 3.7× · 761 µs ±2% 3.0× · 628 µs ±2%
List of 100 rows 377 µs 3.1× · 1.18 ms ±2% 3.5× · 1.30 ms ±6% 3.8× · 1.42 ms ±2% 4.7× · 1.77 ms ±4% 3.0× · 1.13 ms ±5%
List of 1000 rows 2.68 ms 2.8× · 7.54 ms ±4% 3.2× · 8.55 ms ±4% 3.7× · 9.87 ms ±4% 2.8× · 7.62 ms ±7% 1.9× · 4.95 ms ±5%
100 rows fetched again 381 µs 2.0× · 774 µs ±6% 2.1× · 792 µs ±4% 2.6× · 987 µs ±4% 4.6× · 1.76 ms ±3% 3.0× · 1.16 ms ±5%
100 rows as arrays 251 µs 2.5× · 637 µs ±3% 2.8× · 706 µs ±2% 3.2× · 793 µs ±3% 3.9× · 987 µs ±7% 4.4× · 1.10 ms ±3%
Eager belongs-to, 100 posts 843 µs 3.2× · 2.73 ms ±3% 3.5× · 2.98 ms ±6% 2.6× · 2.23 ms ±6% 4.6× · 3.91 ms ±3% 2.7× · 2.26 ms ±7%
Eager has-many, 20 users 1.11 ms 3.0× · 3.35 ms ±2% 3.1× · 3.45 ms ±4% 3.1× · 3.43 ms ±3% 4.0× · 4.43 ms ±3% 2.5× · 2.79 ms ±4%
Lazy belongs-to, 100 posts 1.95 ms 2.1× · 4.05 ms ±4% 2.2× · 4.25 ms ±4% 2.6× · 5.06 ms ±2% 31.4× · 61.37 ms ±1% 26.9× · 52.52 ms ±0%
All 10 000 posts 30.78 ms 3.1× · 95.08 ms ±4% 3.4× · 103.70 ms ±3% 3.3× · 101.23 ms ±5% 2.8× · 86.26 ms ±3% 2.0× · 61.41 ms ±3%
Insert 100 users 15.99 ms 1.5× · 24.30 ms ±3% 3.5× · 55.89 ms ±1% 2.4× · 38.71 ms ±2% 3.8× · 61.20 ms ±1% 3.2× · 50.44 ms ±1%
Insert 20 users + 100 posts 21.21 ms 1.5× · 31.76 ms ±1% 1.8× · 39.08 ms ±1% 2.4× · 49.86 ms ±1% 3.7× · 77.83 ms ±1% 2.9× · 62.46 ms ±1%
Update 100 users 15.31 ms 1.8× · 26.96 ms ±2% 3.8× · 58.17 ms ±1% 1.8× · 27.01 ms ±2% 4.0× · 61.35 ms ±1% 3.3× · 51.06 ms ±1%
Delete 100 posts 13.74 ms 1.6× · 22.21 ms ±2% 3.9× · 53.60 ms ±1% 1.8× · 24.17 ms ±1% 3.9× · 53.08 ms ±0% 3.4× · 46.58 ms ±2%

Peak memory of the process loading all 10 000 posts:

PDO Cycle DataMapper Cycle ActiveRecord Doctrine ORM Eloquent Yii ActiveRecord
13.6 MiB 33.8 MiB 37.2 MiB 22.1 MiB 21.9 MiB 18.1 MiB

MySQL

PHP 8.5.13, MySQL 8.4.13, Linux 7.0.0-1018-aws, 2026-12-02. Each cell: time relative to hand-written PDO (lower is better), then the time per operation and its relative standard deviation. PDO runs alongside every contender on the same runner; the PDO column is the median of those runs.

Scenario PDO Cycle DataMapper 2.19.1 Cycle ActiveRecord 1.2.1 Doctrine ORM 3.8.0 Eloquent 13.45.0 Yii ActiveRecord 1.1.0
Find by primary key 62.5 µs 2.1× · 133 µs ±12% 2.6× · 161 µs ±8% 2.3× · 144 µs ±7% 3.8× · 236 µs ±4% 2.3× · 143 µs ±8%
List of 10 rows 75.7 µs 3.1× · 232 µs ±7% 3.3× · 253 µs ±6% 3.6× · 271 µs ±6% 4.7× · 354 µs ±4% 2.6× · 196 µs ±8%
List of 100 rows 197 µs 3.8× · 749 µs ±8% 4.5× · 891 µs ±6% 4.4× · 869 µs ±6% 5.1× · 998 µs ±5% 2.7× · 529 µs ±7%
List of 1000 rows 1.58 ms 3.0× · 4.67 ms ±1% 3.4× · 5.41 ms ±2% 3.5× · 5.55 ms ±8% 2.8× · 4.35 ms ±2% 1.7× · 2.66 ms ±4%
100 rows fetched again 237 µs 2.1× · 487 µs ±8% 2.0× · 481 µs ±6% 2.5× · 584 µs ±6% 4.2× · 994 µs ±5% 2.3× · 535 µs ±5%
100 rows as arrays 138 µs 3.3× · 451 µs ±9% 3.2× · 442 µs ±7% 3.6× · 498 µs ±7% 3.3× · 462 µs ±7% 4.0× · 549 µs ±11%
Eager belongs-to, 100 posts 350 µs 5.1× · 1.78 ms ±4% 5.4× · 1.87 ms ±5% 3.5× · 1.21 ms ±2% 6.6× · 2.30 ms ±4% 3.2× · 1.11 ms ±10%
Eager has-many, 20 users 704 µs 3.4× · 2.37 ms ±2% 3.5× · 2.46 ms ±4% 2.9× · 2.02 ms ±2% 4.0× · 2.83 ms ±4% 2.1× · 1.51 ms ±4%
Lazy belongs-to, 100 posts 909 µs 2.4× · 2.19 ms ±4% 2.5× · 2.32 ms ±5% 2.8× · 2.53 ms ±5% 22.5× · 20.45 ms ±2% 10.1× · 9.14 ms ±5%
All 10 000 posts 14.38 ms 3.4× · 49.11 ms ±3% 3.8× · 55.25 ms ±1% 3.8× · 54.54 ms ±1% 2.9× · 41.97 ms ±1% 2.0× · 28.52 ms ±3%
Insert 100 users 6.49 ms 1.7× · 10.72 ms ±2% 4.5× · 29.21 ms ±3% 1.4× · 9.34 ms ±2% 3.9× · 25.31 ms ±2% 1.5× · 9.69 ms ±4%
Insert 20 users + 100 posts 8.87 ms 1.7× · 14.93 ms ±1% 2.4× · 21.00 ms ±3% 1.4× · 11.97 ms ±4% 3.8× · 33.86 ms ±2% 1.4× · 12.50 ms ±4%
Update 100 users 7.88 ms 2.0× · 15.39 ms ±2% 4.5× · 35.46 ms ±2% 1.3× · 10.29 ms ±3% 3.4× · 26.75 ms ±2% 1.5× · 11.50 ms ±3%
Delete 100 posts 7.07 ms 1.7× · 11.72 ms ±2% 4.1× · 28.95 ms ±2% 1.4× · 9.61 ms ±2% 2.9× · 20.46 ms ±1% 1.3× · 9.17 ms ±2%

Peak memory of the process loading all 10 000 posts:

PDO Cycle DataMapper Cycle ActiveRecord Doctrine ORM Eloquent Yii ActiveRecord
16.7 MiB 33.8 MiB 37.3 MiB 25.3 MiB 21.9 MiB 18.9 MiB

How it works

  • Same data. 1000 users with 10 posts each. SQLite lives in memory and every benchmark process fills its own copy; PostgreSQL and MySQL are filled once per run by bin/seed.
  • Same work. Every contender implements the operations of OrmBench, and bin/verify checks before each run that it loads and writes exactly the rows the PDO baseline does.
  • One process per contender. Each ORM lives in contenders/<name> with its own composer.json, so their dependencies never meet. PHPBench runs every iteration in a fresh process.
  • Relative to PDO. Each ORM runs together with the PDO baseline, all of one database on the same runner, and the tables show ORM time divided by the median PDO time of those runs. The ratio can be compared across databases and runners, where absolute times can't; the absolute time and its relative standard deviation are shown next to it.
  • PDO at its best. The baseline uses prepared statements and one round trip per row written: INSERT … RETURNING id on PostgreSQL, where lastInsertId() would query the sequence again.
  • Reads start cold. The identity map is cleared before each read, except in "100 rows fetched again", which repeats a query while its entities are still loaded.
  • Writes are rolled back. Each write runs in a transaction that is rolled back, so the data never drifts.
  • Production-like setup. OPcache on, Xdebug off; Doctrine caches metadata and DQL in memory, as a production setup would.

Scenarios

Scenario What it does
Find by primary key One user by id
List of 10 / 100 / 1000 rows The first users ordered by id
100 rows fetched again The same 100 users while they are still in the identity map
100 rows as arrays 100 users through the ORM query layer, without entities
Eager belongs-to, 100 posts 100 posts with their authors loaded up front (10 distinct users)
Eager has-many, 20 users 20 users with all their posts (200 posts)
Lazy belongs-to, 100 posts 100 posts, then each author through the relation
All 10 000 posts Every post at once; the memory table comes from this one
Insert 100 users 100 new users saved
Insert 20 users + 100 posts 20 users with 5 posts each saved together
Update 100 users Load 100 users, change a field, save
Delete 100 posts Load 100 posts, delete each one

Differences between the ORMs that show in the numbers

  • Identity map. Cycle (both modes) and Doctrine keep one object per row: a lazy relation loads each of the 10 authors once, and a repeated query reuses the loaded entities. Eloquent and Yii ActiveRecord have no identity map: a lazy relation queries once per post (100 queries), and a repeated query builds new models.
  • Lazy relations. With Cycle DataMapper (PromiseMapper) a lazy relation holds a Promise the code calls fetch() on; Cycle ActiveRecord and Doctrine put a proxy object there; Eloquent and Yii load it on property or method access.
  • Eager loading. Cycle and Doctrine join the author into the posts query; Cycle loads a has-many collection with a second query, Doctrine fetch-joins it. Eloquent and Yii load every eager relation with a second query.
  • Writing. The data mappers collect the changes and flush them in one unit of work: one run() for Cycle DataMapper, one flush() for Doctrine. The ActiveRecords save one record per call, each in its own unit of work: saveOrFail() for Cycle ActiveRecord, save() for Eloquent and Yii.
  • Saving a graph. Both Cycle modes and Doctrine save the posts by cascade from their user; with Eloquent the posts are saved through the relation, with Yii one by one.

Running locally

Requires PHP 8.5 with pdo_sqlite (and pdo_pgsql, pdo_mysql for those databases).

composer install
for c in contenders/*/; do composer install --working-dir="$c"; done

php bin/verify                  # every contender does the same work as PDO
php bin/run                     # all contenders on SQLite: results/sqlite/*.xml
php bin/report                  # the tables
php bin/report --json=results.json && php bin/validate results.json

docker compose up -d --wait     # PostgreSQL on 15432, MySQL on 13306
DB=pgsql php bin/run cycle doctrine -- --iterations=5

bin/run passes everything after -- to PHPBench. The connection is set by DB (sqlite, pgsql, mysql) and DB_HOST, DB_PORT, DB_NAME, DB_USER, DB_PASSWORD.

Adding a contender

  1. Create contenders/<name> with a composer.json that autoloads DbInterop\Benchmarks\<Name>\ from src/.
  2. Put the entities into src/ and a bench/<Name>Bench.php extending OrmBench.
  3. Register it in Contenders and make php bin/verify <name> pass.

About

Benchmarks of PHP ORMs on the same scenarios, against hand-written PDO

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages