Skip to content

Repository files navigation

PHP ORM and SQL Benchmarks

This is a modern benchmark for PHP ORM implementations and SQL servers.

Currently benchmarked PHP ORMs include:

Currently supported SQL implementations include:

1. Methodology

This project uses a modified version of the NorthWind database schema from Microsoft Access.

Testing includes insertion, update, read, delete, and large dataset iterations.

Tests should be run on the same machine at the same time. The idea is not to care about a specific machine's performance, but rather the relative performance of different SQL servers and PHP ORM implementations on the same machine.

Tests can be taylored to include or exclude specific servers, orms and iterations.

2. Requirements

3. Installation

git clone https://github.com/phpfui/php-sql-orm-benchmarks.git
cd php-sql-orm-benchmarks
composer install

4. Configuration

Tests are configured via the config.php file. The namespace must contain a Tests class which extends the \SOB\Test abstract class.

return [
'iterations' => 5000, // default is 5000'tests' => [
['namespace' => 'PHPFUI', 'description' => 'sqlite::memory:', 'dbname' => ':memory:'],
['namespace' => 'PHPFUI', 'description' => 'sqlite file', ],
['namespace' => 'PHPFUI', 'description' => 'MySQL', 'driver' => 'mysql', ],
['namespace' => 'PHPFUI', 'description' => 'MariaDB', 'driver' => 'mysql', 'port' => 3307,],
['namespace' => 'Eloquent', 'description' => 'sqlite::memory:', 'dbname' => ':memory:'],
['namespace' => 'Eloquent', 'description' => 'sqlite file', ],
['namespace' => 'Eloquent', 'description' => 'MySQL', 'driver' => 'mysql', ],
['namespace' => 'Eloquent', 'description' => 'MariaDB', 'driver' => 'mysql', 'port' => 3307,],
],
];

The following options are available:

  • namespace, default PHPFUI
  • description, PDO connection string
  • dbname, default namespace
  • driver, default 'sqlite'
  • host, default 'localhost'
  • port, default 3306
  • user, default root
  • password, default ''

Create databases to match namespaces for each SQL server you want to test. Without a configuration file, sqlite::memory: and sqlite file will be used for all instances of the Tests class.

see config.example.php for all current tests.

5. Running All The Benchmarks

php benchmark.php

6. More Accurate Benchmarking

The above will run all tests sequentially. but previous tests can affect subsequent tests. While this is good for debugging the test suite, in order to get a better benchmark, you should run each test individually.

By passing the array offset of the test to run, you can run tests individually from the command line. For example:

php benchmark.php 0
php benchmark.php 1
php benchmark.php 2
php benchmark.php 3
php benchmark.php 4
php benchmark.php 5
php benchmark.php 6
php benchmark.php 7

7. Results

Results after each run are appended to the results.csv file. Delete the file to start fresh. Use the csvToMDTable.php file to create a nice MarkDown table like this:

Date/TimeSystemPHPTestDescriptionInit TimeInit MemoryInsert TimeInsert MemoryRead TimeRead MemoryUpdate TimeUpdate MemoryUpdate Test TimeUpdate Test MemoryRandom Read TimeRandom Read MemoryDelete TimeDelete MemoryTotal Runtime TimeTotal Runtime Memory
2024-12-24 21:35:39Windows NT 10.0 build 26100 (Windows 11) AMD648.4.0Cakesqlite::memory:0.38640724525284.798766471727602.8997750-33138164.556418042506084.1355289-32581040.35619804373448.566341889534425.69956296642120
2024-12-24 21:36:05Windows NT 10.0 build 26100 (Windows 11) AMD648.4.0Cakesqlite file0.564963035045.7709075-32808243.996320643899124.4525825-34526323.122383744450880.33508544373447.957825277686426.20019843321672
2024-12-24 21:36:31Windows NT 10.0 build 26100 (Windows 11) AMD648.4.0CakeCachedsqlite::memory:0.012203042082.9163795169201.6817722-802.3998698-801.3207647-800.1484511-803.7483831-8012.227898923144
2024-12-24 21:36:43Windows NT 10.0 build 26100 (Windows 11) AMD648.4.0CakeCachedsqlite file0.496293042642.2587298169201.5141711-802.4559431-801.2716724-800.1383385-803.7262737-8011.861495423200
2024-12-24 21:36:55Windows NT 10.0 build 26100 (Windows 11) AMD648.4.0Doctrinesqlite::memory:0.07031012842624300.562340265696080.01093601000505.3371687404960.0117593-800.0013659-80269.0243543-107353441,075.0183673-1279360
2024-12-24 21:54:50Windows NT 10.0 build 26100 (Windows 11) AMD648.4.0Doctrinesqlite file0.00799496768227.3766263122576160.0188366-80462.4604857407120.0086476-800.0009674-80213.0787087-11112456902.95238021194816
2024-12-24 22:09:53Windows NT 10.0 build 26100 (Windows 11) AMD648.4.0Eloquentsqlite::memory:0.698910122954641.215984516663840.7744099997602.1031329659360.7071536-800.0861693-802.0346760807.62054554129880
2024-12-24 22:10:01Windows NT 10.0 build 26100 (Windows 11) AMD648.4.0Eloquentsqlite file0.4894172620037.826734010001.1614052037.2059720801.1111649-800.1163515-8040.2058679400118.11700419936
2024-12-24 22:11:59Windows NT 10.0 build 26100 (Windows 11) AMD648.4.0PHPFUIsqlite::memory:0.0097072716800.2245116991840.1674389-2480.44704428320.1663797-9920.0166409-800.3135178-801.3453434172712
2024-12-24 22:12:00Windows NT 10.0 build 26100 (Windows 11) AMD648.4.0PHPFUIsqlite file0.4429463133637.26595116080.5252738-24861.00935818320.5912322-9920.0521919-8075.6630321-80175.55010973792

8. Contributions

If you are the developer or user of an ORM, data mapper, Active Record library and you want to have it included in this repo, please submit a pull-request.

Slight changes to the database schema are allowed and supported as long as the new schema is functionally equivalent.

If you see something wrong about the current usage of one of the libraries, please send a pull-request along with a short explanation of what that change does.

Please, try to implement the solutions using the most common configuration. If you want to include an optimized version of the test, create another namespace for the Tests class.

9. In Progress

The /inProgress directory contains non-working benchmark code that I could not get working, either due to imcompatiblies with the testing suite (the package was not sufficiently configurable), errors in the package, or my lack of understanding on how to use the package. PRs welcome to update these tests to working code.

10. Future Enhancements

Artificial benchmarks can only provide so much insight into how a particular ORM performs on a particular SQL schema. Please feel free to add additional tests to further test these ORMs. Or add your favorate ORM. All PRs welcome.

11. Disclaimer

Inclusion or omission of any particular ORM is not an endorsement or disapproval of any ORM.

About

Benchmark for PHP ORMs and SQL Databases

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages