Benchmarks run Sept. 17, 2026 · PHP · PostgreSQL · performance

Eloquent vs. Doctrine ORM on PostgreSQL

In the benchmark, Eloquent read 10,000 objects 1.5 times as fast, and Doctrine handled repeated find() calls 19.6 times as fast.

In my benchmark, Eloquent read 10,000 objects in 154.7 ms and Doctrine took 229.5 ms. Repeated lookups by ID reversed the result. Doctrine finished in 32.1 ms and Eloquent took 629.6 ms.

Some colleagues said that Eloquent was slow, so they preferred to start with Doctrine. Active Record, Data Mapper, and magic attributes kept coming up. I wanted to see which operations made those differences visible, so I set up a single PostgreSQL database and measured reads, relationship traversal, and writes with both ORMs.

How I ran the benchmark

The benchmark used Docker on one machine. PHP 8.4.25 ran with OPcache on and JIT off, with PostgreSQL 17.11 in a neighboring container. I ran Eloquent from Laravel 13 (illuminate/database 13.32.0) through Capsule without bootstrapping Laravel. Doctrine ORM 3.7.1 ran in production mode with DBAL 4.4.4, APCu for metadata and query caches, and native PHP lazy objects. The second-level cache was off. I kept model events and casts on in Eloquent and change tracking on in Doctrine.

Both ORMs used the same tables and foreign key indexes. I seeded 10,000 users, ten posts per user, and five comments per post, for a total of 610,000 rows. I ran ANALYZE after seeding.

Each variant had three warmup iterations followed by 15 measured iterations, or five to seven for the heavier scenarios. The tables report the median of the three run medians. Where the harness compared checksums, they matched. I measured database access time separately with DB::listen() in Eloquent and DBAL middleware in Doctrine. The memory figures are peaks reported by PHP in a separate run of each variant.

Reading rows into objects

Each ORM loaded users with a single query, then iterated over the result and summed their ratings.

Variant1,000 objects10,000 objectsPeak memory at 10,000
Eloquent15.8 ms154.7 ms16.1 MiB
Doctrine21.8 ms229.5 ms25.6 MiB

At 10,000 rows, Eloquent took about a third less time and used 37% less memory. The measurement includes the query, hydration, and iteration. During hydration, Doctrine registers each entity in its identity map and takes a snapshot of the fields for change tracking. Eloquent fills in the model's attributes and keeps their original values on the model itself.

For a report or export, I also measured ways to read the rows without creating models or entities.

ORMModels or entitiesRead modeTime in that mode
Eloquent154.7 mstoBase()->get()30.7 ms
Doctrine229.5 msgetArrayResult()143.0 ms

toBase()->get() returned plain objects and cut Eloquent's time by 80%. getArrayResult() used an array hydrator and cut Doctrine's time by 38%. Each percentage compares two paths in the same ORM. The two read modes return different data structures.

The cost of reading one field

I read the same field a million times on a model and on an entity. Each measurement included one initial lookup by ID.

Access pathTotal time including lookupApproximate time per access
Eloquent, $model->name2,069.6 ms≈2,070 ns
Eloquent, $model->getAttributes()['name']143.7 ms≈144 ns
Doctrine, $entity->name8.9 ms≈9 ns

The microbenchmark produced a gap of about 230×. Doctrine reads a public property. Eloquent goes through __get() and getAttribute(), which determine how to handle the attribute. The field in this test had no accessor. getAttributes() exposes the internal array. For a field with a cast or an accessor, the value in the array can differ from the one returned by property access.

Repeated lookups and stale data

Within one iteration I called find() for the same 100 user IDs ten times.

VariantTimeQueriesDatabase access time
Eloquent629.6 ms1,000518.5 ms
Doctrine32.1 ms10025.7 ms

With the same EntityManager, Doctrine returned objects from the identity map on subsequent calls. Eloquent issued a query on every call. Doctrine took about one-twentieth of the time, with database access accounting for most of the gap.

I then loaded a post with views = 1 and used a single query to set views = 777 on ten posts. The object already loaded in each test kept the old value. Then I called find() again.

Value readEloquent bulk update()Doctrine DQL UPDATE
In the previously loaded object11
Returned by another call to find()7771
A second find() after a bulk update PostgreSQL stores views = 777. Both loaded objects still hold views = 1.
Eloquent
  1. find() Sends a SELECT to PostgreSQL.
  2. New model views = 777
Doctrine
  1. find() Returns the same object from the identity map with views = 1.
  2. refresh() Reads the row from PostgreSQL. The same object now holds views = 777.

Doctrine returned the same object. After refresh(), it showed 777. If a decision in the same operation depends on the updated value, refresh the managed entity before reading it.

One query or two

I compared ways of loading posts for 500 users. The two-query Doctrine variant loaded the users and posts separately and summed the views directly from the list of posts. I traversed the posts through each user's relationship in the with() and fetch join variants.

VariantTimeQueriesPeak memory
Eloquent, with('posts')125.5 ms214.3 MiB
Doctrine, two separate queries148.7 ms220.5 MiB
Doctrine, fetch join196.0 ms120.7 MiB

The JOIN result repeats the user's columns for each post, and the hydrator uses those rows to assemble the object graph. The two-query variant skips that work. If the application needs the object graph, include the cost of assembling it when comparing the two approaches.

For user → posts → comments over 50 users, Eloquent used with('posts.comments') to run three queries in 65.4 ms. Doctrine ran one in 121.7 ms with a two-level fetch join. Lazy loading took 551 queries with each ORM, finishing in 395.0 ms with Eloquent and 249.5 ms with Doctrine.

The database ran on the same machine. With higher network latency, an extra query can cost more than transferring repeated data in the JOIN result.

Writes and the size of the unit of work

I loaded the objects ahead of time, changed one field on one of them, and saved it. The timer covered changing the field, saving it, and rolling back the test transaction. It started after I loaded the objects.

VariantTimeOperations counted
Eloquent, save() with 1,000 models loaded1.5 ms1
Doctrine, flush() with 1,000 managed entities9.7 ms3
Doctrine, flush() with one managed entity0.8 ms3

With the default change tracking policy, Doctrine checks its managed entities on flush(). With 1,000 entities, the measured operation took about 12 times as long as it did with one entity. The counter recorded three operations in both cases. Eloquent's save() saves the individual model. If a Doctrine worker processes many entities in one EntityManager, keep an eye on the size of its unit of work between batches.

In the insert test, each variant wrote 1,000 rows in a transaction that I rolled back.

VariantTimeOperations counted
Eloquent, create() in a loop725.6 ms1,000
Doctrine, persist() and flush() in batches of 100416.5 ms1,020
Eloquent, one insert() call30.3 ms1

Doctrine reuses prepared statements for entity inserts. The insert() variant sends one SQL statement and bypasses model creation and model events. It fits jobs that only need to insert the rows.

I also checked Eloquent's regular save(). Changing one field resulted in an update to that field and updated_at. Assigning the field its existing value yielded no UPDATE. With $touches set, loading and saving a post took four queries instead of two. Eloquent also loaded the relationship and updated the parent's timestamp.

An exception before the third write

In the final check, I prepared two related records and threw an exception before the third. The harness checked which rows the same connection could see, then rolled back the outer test transaction.

Rows visible before rollbackEloquent after two create() callsDoctrine after two persist() calls, before flush()
Users10
Posts10
When the inserts run The harness checks the rows using the same connection before it rolls back the test transaction.
Eloquent
  1. create() the user Executes an INSERT for the user.
  2. create() the post Executes an INSERT for the post.
  3. Exception before the third write One user and one post are visible.
Doctrine
  1. persist() the user Schedules an insert for the user.
  2. persist() the post Schedules an insert for the post.
  3. Exception before flush() No new rows are visible.

Each create() inserted a row immediately. Doctrine scheduled both inserts, and execution stopped before flush(). To make several writes atomic in Laravel, put them in DB::transaction() and let the exception propagate out of the callback. Doctrine wraps the writes of a single flush() in a transaction. This test checked the state before flush().

What to check in your application

For a list page, I would start with the shape of the result and how it loads relationships. For a worker, I would record the size of the unit of work and measure how long flush() takes near the end of a batch. If a bulk UPDATE can run between reads, add a test for what a second call to find() returns.

Next step

Run the 7-identity-map scenario using the repository instructions and compare the query counts. In my run, Eloquent issued 1,000 queries and Doctrine issued 100. Benchmark code, setup instructions, and the three original runs.

Review your PHP application’s performance

I can help trace queries, review relationship loading, and investigate slow writes.