Assert execution time of bulk inserts, searches, and other performance-critical operations.
Performance Testing
class PerformanceTest extends TestCase {
public function testBulkInsertIsFast(): void {
$start = microtime(true);
$repo = new UserRepository($this->pdo);
for ($i = 0; $i < 1000; $i++) {
$repo->create(["name" => "User $i", "email" => "user$i@test.com"]);
}
$elapsed = microtime(true) - $start;
$this->assertLessThan(2.0, $elapsed, "Bulk insert took too long");
}
public function testQueryIsFast(): void {
// Seed 10,000 rows
$this->seedLargeDataset();
$start = microtime(true);
$results = (new UserRepository($this->pdo))->search("Alice");
$elapsed = microtime(true) - $start;
$this->assertLessThan(0.1, $elapsed, "Search query is too slow");
$this->assertNotEmpty($results);
}
}