Skip to content

PHP ORM Performance Analysis: Benchmarking and comparing Doctrine, Laravel, Cycle, and CompositePHP ORMs in CRUD operations on MySQL. Essential insights on speed and memory efficiency for PHP developers.

Notifications You must be signed in to change notification settings

laylatichy/php-orm-benchmark

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP ORM Benchmark

Overview

This repository contains benchmarks for some of the most popular PHP ORMs, used as a reference for performance optimizations in my personal project compositephp/db.

The ORMs benchmarked include:

Methodology

The benchmark executes 10 000 CRUD (Create, Read, Update, Delete) operations to assess the performance of each ORM. Operations include:

  1. Creating a new record in the database.
  2. Reading the record by primary key.
  3. Updating one field for the found record.
  4. Deleting the record.

Database

  • MySQL 8.0
  • Table used for the benchmark:
CREATE TABLE IF NOT EXISTS Users
(
    `id` INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `name` VARCHAR(255) NOT NULL,
    `age` INTEGER NOT NULL,
    `microtime` FLOAT NOT NULL,
    `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL
);

Hardware

MacBook Pro with Apple M2 Pro Chip and 12‑Core CPU.

Results

The following table summarizes the performance of each ORM in terms of execution time, memory usage, and peak memory usage:

ORM Time (seconds) Memory Kb Memory Peak Mb
Laravel ORM 61.51 4950.91 8.063
Cycle ORM 44.32 288.15 7.007
Doctrine ORM 37.45 870.24 6.408
CompositePHP 24.71 143.46 2.217

Running Locally

Requirements

  • PHP 8.1+
  • Docker
  • Composer
  • PDO_MySQL extension

Steps

  1. Clone or download this repository
  2. Run composer update
  3. Execute docker-compose up
  4. Run benchmarks for each ORM separately:
    • php src/test-laravel.php
    • php src/test-cycle.php
    • php src/test-doctrine.php
    • php src/test-composite.php

Note

This is a synthetic benchmark focused on speed and memory consumption and does not compare the feature list of the ORMs. Feel free to note any problems, inaccuracies, or shortcomings in using these ORMs and make a pull request to fix them.

About

PHP ORM Performance Analysis: Benchmarking and comparing Doctrine, Laravel, Cycle, and CompositePHP ORMs in CRUD operations on MySQL. Essential insights on speed and memory efficiency for PHP developers.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%