Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ gtag('config', 'G-VYGDN3X0PR');`],
nav: [
{ text: 'Docs', link: '/docs/intro/getting-started.md' },
{ text: 'Blog', link: '/blog/' },
{ text: 'Benchmarks', link: '/benchmarks/', activeMatch: '^/benchmarks/' },
],
editLink: {
pattern: 'https://github.com/php-testo/php-testo.github.io/edit/master/:path',
Expand Down Expand Up @@ -154,6 +155,15 @@ gtag('config', 'G-VYGDN3X0PR');`],
items: [],
},
],
'/benchmarks/': [
{
text: 'Benchmarks',
link: '/benchmarks/',
items: [
{ text: 'ORM', link: '/benchmarks/orm.md' },
],
},
],
},
},
},
Expand All @@ -170,6 +180,7 @@ gtag('config', 'G-VYGDN3X0PR');`],
nav: [
{ text: 'Документация', link: '/ru/docs/intro/getting-started.md' },
{ text: 'Блог', link: '/ru/blog/' },
{ text: 'Бенчмарки', link: '/ru/benchmarks/', activeMatch: '^/ru/benchmarks/' },
],
editLink: {
pattern: 'https://github.com/php-testo/php-testo.github.io/edit/master/:path',
Expand Down Expand Up @@ -239,6 +250,15 @@ gtag('config', 'G-VYGDN3X0PR');`],
items: [],
},
],
'/ru/benchmarks/': [
{
text: 'Бенчмарки',
link: '/ru/benchmarks/',
items: [
{ text: 'ORM', link: '/ru/benchmarks/orm.md' },
],
},
],
},
outline: {
label: 'На этой странице',
Expand Down
994 changes: 994 additions & 0 deletions .vitepress/theme/OrmBenchmarks.vue

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions .vitepress/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import BlogSponsor from './BlogSponsor.vue'
import GitHubStars from './GitHubStars.vue'
import CodeTabs from './CodeTabs.vue'
import HomeBench from './HomeBench.vue'
import OrmBenchmarks from './OrmBenchmarks.vue'
import JetBrainsPluginButton from './JetBrainsPluginButton.vue'
import JetBrainsPlugin from './JetBrainsPlugin.vue'
import OpenIdePluginButton from './OpenIdePluginButton.vue'
Expand Down Expand Up @@ -156,6 +157,7 @@ export default {
enhanceApp({ app, router }) {
app.component('CodeTabs', CodeTabs)
app.component('HomeBench', HomeBench)
app.component('OrmBenchmarks', OrmBenchmarks)
app.component('JetBrainsPluginButton', JetBrainsPluginButton)
app.component('JetBrainsPlugin', JetBrainsPlugin)
app.component('OpenIdePluginButton', OpenIdePluginButton)
Expand Down
72 changes: 72 additions & 0 deletions .vitepress/theme/orm-benchmarks.data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { readFileSync } from 'node:fs'
import { basename } from 'node:path'

/**
* The runs of php-testo/benchmarks-orm, one file per release in `data/benchmarks/orm/`. The Publish workflow of that
* repository adds them after validating each against its schema; the checks here only make sure a file the page
* can't render fails the build instead of the page.
*/

export type ScenarioGroup = 'read' | 'relations' | 'bulk' | 'write'

export interface Measurement {
/** Microseconds per operation. */
time: number
rstdev: number
/** Peak memory of the process, bytes. */
memory: number
/** The time divided by the PDO baseline. */
ratio: number
}

export interface Database {
id: 'sqlite' | 'pgsql' | 'mysql'
label: string
server: string
date: string
machine: { cpu: string, cores: number, os: string, runner: string | null, php: string }
baseline: Record<string, { time: number, memory: number, runs: number }>
results: Record<string, Record<string, Measurement>>
}

export interface Run {
schema: 1
release: string
date: string
source: { repository: string, commit: string | null, run: string | null }
php: string
scenarios: { id: string, group: ScenarioGroup, label: string, revs: number, iterations: number }[]
contenders: { id: string, label: string, package: string, version: string }[]
databases: Database[]
}

declare const data: Run[]
export { data }

function check(run: Run, file: string): Run {
const fail = (what: string): never => {
throw new Error(`${file}: ${what}`)
}
run.schema === 1 || fail(`schema ${run.schema}, the page renders schema 1`)
basename(file, '.json') === run.release || fail(`holds release ${run.release}`)
Number.isNaN(Date.parse(run.date)) && fail(`bad date ${run.date}`)
run.scenarios?.length && run.contenders?.length && run.databases?.length || fail('no scenarios, contenders or databases')
for (const db of run.databases) {
for (const scenario of run.scenarios) {
db.baseline[scenario.id]?.time > 0 || fail(`${db.id}: no PDO time for ${scenario.id}`)
for (const contender of run.contenders) {
db.results[contender.id]?.[scenario.id]?.ratio > 0 || fail(`${db.id}: no ${contender.id} result for ${scenario.id}`)
}
}
}
return run
}

export default {
watch: ['../../data/benchmarks/orm/*.json'],
load(files: string[]): Run[] {
return files
.map(file => check(JSON.parse(readFileSync(file, 'utf-8')), file))
.sort((a, b) => Date.parse(b.date) - Date.parse(a.date))
},
}
12 changes: 12 additions & 0 deletions benchmarks/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Benchmarks
description: Benchmarks of the PHP ecosystem run by the Testo team, with every run published and kept.
outline: false
editLink: false
---

# Benchmarks

Measurements of PHP libraries on the same scenarios, run on GitHub-hosted runners and republished with every new version of the libraries under test. Each benchmark lives in its own repository, so you can read the code, run it yourself and propose a fix. Every published run stays here: open any earlier one to see how the numbers changed between versions.

- **[ORM](./orm.md)** — Cycle ORM, Doctrine, Eloquent and Yii ActiveRecord against hand-written PDO on SQLite, PostgreSQL and MySQL.
26 changes: 26 additions & 0 deletions benchmarks/orm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
title: PHP ORM Benchmarks
description: Cycle ORM, Doctrine, Eloquent and Yii ActiveRecord compared on the same scenarios against hand-written PDO, on SQLite, PostgreSQL and MySQL.
aside: false
outline: false
editLink: false
---

# PHP ORM Benchmarks

How much an ORM costs compared to the queries you would write by hand. Every ORM runs the same scenarios on the same data, and every result is divided by the time of hand-written PDO measured on the same machine in the same run: `3.0×` means three times slower than plain PDO.

The numbers come from [php-testo/benchmarks-orm](https://github.com/php-testo/benchmarks-orm). Each release of that repository benchmarks the ORM versions it pins and publishes the run here, so you can go back to any earlier run and see how the ORMs changed between versions.

<OrmBenchmarks />

## How it is measured

- **Same data.** 1000 users with 10 posts each. SQLite lives in memory; PostgreSQL and MySQL run as services next to the runner.
- **Same work.** Before measuring, every ORM is checked against PDO: the same rows loaded, the same rows written, everything rolled back.
- **Isolated processes.** Each ORM has its own Composer project, and [PHPBench](https://github.com/phpbench/phpbench) runs every iteration in a fresh process with OPcache on. The time shown is the mode of the iterations.
- **Fair baseline.** PDO runs next to every ORM on the same runner; the baseline is the median of those runs, so one noisy run can't skew the ratios.
- **Writes leave no trace.** Inserts, updates and deletes run in a transaction that is rolled back.
- **GitHub-hosted runners.** Absolute times move between runner machines; compare ratios rather than microseconds across runs.

The scenarios, the entity mappings and the exact settings are in the [repository](https://github.com/php-testo/benchmarks-orm#how-it-works). Spotted something unfair to one of the ORMs? [Open an issue](https://github.com/php-testo/benchmarks-orm/issues).
Loading