From f0b0062a35f38e256022be01952cf01e269f9900 Mon Sep 17 00:00:00 2001 From: Mark Date: Tue, 10 Mar 2026 09:26:18 +0100 Subject: [PATCH] perf(database): add query execution benchmark --- .../Database/QueryExecutionBench.php | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 tests/Benchmark/Database/QueryExecutionBench.php diff --git a/tests/Benchmark/Database/QueryExecutionBench.php b/tests/Benchmark/Database/QueryExecutionBench.php new file mode 100644 index 0000000000..1772b5514a --- /dev/null +++ b/tests/Benchmark/Database/QueryExecutionBench.php @@ -0,0 +1,83 @@ +connect(); + + $this->database = new GenericDatabase( + $connection, + new GenericTransactionManager($connection), + new SerializerFactory($container), + ); + + $container->singleton(Database::class, $this->database); + GenericContainer::setInstance($container); + + $this->database->execute(new Query('CREATE TABLE IF NOT EXISTS bench (id INTEGER PRIMARY KEY, name TEXT, value TEXT)')); + + foreach (range(1, 100) as $i) { + $this->database->execute(new Query( + 'INSERT INTO bench (name, value) VALUES (:name, :value)', + [':name' => "item_{$i}", ':value' => "value_{$i}"], + )); + } + } + + #[BeforeMethods('setUp')] + #[Iterations(5)] + #[Revs(1000)] + #[Warmup(10)] + public function benchExecuteInsert(): void + { + $this->database->execute(new Query( + 'INSERT INTO bench (name, value) VALUES (:name, :value)', + [':name' => 'bench_item', ':value' => 'bench_value'], + )); + } + + #[BeforeMethods('setUp')] + #[Iterations(5)] + #[Revs(1000)] + #[Warmup(10)] + public function benchFetchAll(): void + { + $this->database->fetch(new Query('SELECT * FROM bench')); + } + + #[BeforeMethods('setUp')] + #[Iterations(5)] + #[Revs(1000)] + #[Warmup(10)] + public function benchFetchWithBindings(): void + { + $this->database->fetch(new Query( + 'SELECT * FROM bench WHERE name = :name', + [':name' => 'item_50'], + )); + } +}