Skip to content

Commit 92e9e62

Browse files
authored
Update benchmark configuration (#2921)
* Use native lazy objects in benchmarks * Use phpbench attributes instead of annotation
1 parent 29f18ba commit 92e9e62

File tree

5 files changed

+31
-23
lines changed

5 files changed

+31
-23
lines changed

benchmark/BaseBench.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
use function in_array;
1818
use function iterator_to_array;
1919

20+
use const PHP_VERSION_ID;
21+
2022
/** @BeforeMethods({"initDocumentManager", "clearDatabase"}) */
2123
abstract class BaseBench
2224
{
@@ -45,6 +47,12 @@ public function initDocumentManager(): void
4547
$config->setMetadataDriverImpl(self::createMetadataDriverImpl());
4648
$config->setMetadataCache(new ArrayAdapter());
4749

50+
if (PHP_VERSION_ID >= 80400) {
51+
$config->setUseNativeLazyObject(true);
52+
} else {
53+
$config->setUseLazyGhostObject(true);
54+
}
55+
4856
$client = new Client(
4957
getenv('DOCTRINE_MONGODB_SERVER') ?: self::DEFAULT_MONGODB_SERVER,
5058
[],

benchmark/Document/HydrateDocumentBench.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
use Documents\User;
1010
use MongoDB\BSON\ObjectId;
1111
use MongoDB\BSON\UTCDateTime;
12-
use PhpBench\Benchmark\Metadata\Annotations\BeforeMethods;
13-
use PhpBench\Benchmark\Metadata\Annotations\Warmup;
12+
use PhpBench\Attributes\BeforeMethods;
13+
use PhpBench\Attributes\Warmup;
1414

15-
/** @BeforeMethods({"init"}, extend=true) */
15+
#[BeforeMethods(['init'])]
1616
final class HydrateDocumentBench extends BaseBench
1717
{
1818
/** @var array<string, mixed> */
@@ -78,31 +78,31 @@ public function init(): void
7878
->getHydratorFor(User::class);
7979
}
8080

81-
/** @Warmup(2) */
81+
#[Warmup(2)]
8282
public function benchHydrateDocument(): void
8383
{
8484
self::$hydrator->hydrate(new User(), self::$data);
8585
}
8686

87-
/** @Warmup(2) */
87+
#[Warmup(2)]
8888
public function benchHydrateDocumentWithEmbedOne(): void
8989
{
9090
self::$hydrator->hydrate(new User(), self::$data + self::$embedOneData);
9191
}
9292

93-
/** @Warmup(2) */
93+
#[Warmup(2)]
9494
public function benchHydrateDocumentWithEmbedMany(): void
9595
{
9696
self::$hydrator->hydrate(new User(), self::$data + self::$embedManyData);
9797
}
9898

99-
/** @Warmup(2) */
99+
#[Warmup(2)]
100100
public function benchHydrateDocumentWithReferenceOne(): void
101101
{
102102
self::$hydrator->hydrate(new User(), self::$data + self::$referenceOneData);
103103
}
104104

105-
/** @Warmup(2) */
105+
#[Warmup(2)]
106106
public function benchHydrateDocumentWithReferenceMany(): void
107107
{
108108
self::$hydrator->hydrate(new User(), self::$data + self::$referenceManyData);

benchmark/Document/LoadDocumentBench.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
use Documents\Phonenumber;
1313
use Documents\User;
1414
use MongoDB\BSON\ObjectId;
15-
use PhpBench\Benchmark\Metadata\Annotations\BeforeMethods;
16-
use PhpBench\Benchmark\Metadata\Annotations\Warmup;
15+
use PhpBench\Attributes\BeforeMethods;
16+
use PhpBench\Attributes\Warmup;
1717

1818
use function assert;
1919

20-
/** @BeforeMethods({"init"}, extend=true) */
20+
#[BeforeMethods(['init'])]
2121
final class LoadDocumentBench extends BaseBench
2222
{
2323
/** @var ObjectId */
@@ -53,33 +53,33 @@ public function init(): void
5353
$this->getDocumentManager()->clear();
5454
}
5555

56-
/** @Warmup(2) */
56+
#[Warmup(2)]
5757
public function benchLoadDocument(): void
5858
{
5959
$this->loadDocument();
6060
}
6161

62-
/** @Warmup(2) */
62+
#[Warmup(2)]
6363
public function benchLoadEmbedOne(): void
6464
{
6565
$this->loadDocument()->getAddress()->getCity();
6666
}
6767

68-
/** @Warmup(2) */
68+
#[Warmup(2)]
6969
public function benchLoadEmbedMany(): void
7070
{
7171
$this->loadDocument()->getPhonenumbers()->forAll(static function (int $key, Phonenumber $element) {
7272
return $element->getPhoneNumber() !== null;
7373
});
7474
}
7575

76-
/** @Warmup(2) */
76+
#[Warmup(2)]
7777
public function benchLoadReferenceOne(): void
7878
{
7979
$this->loadDocument()->getAccount()->getName();
8080
}
8181

82-
/** @Warmup(2) */
82+
#[Warmup(2)]
8383
public function benchLoadReferenceMany(): void
8484
{
8585
$this->loadDocument()->getGroups()->forAll(static function (int $key, Group $group) {

benchmark/Document/StoreDocumentBench.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
use Documents\Group;
1212
use Documents\Phonenumber;
1313
use Documents\User;
14-
use PhpBench\Benchmark\Metadata\Annotations\Warmup;
14+
use PhpBench\Attributes\Warmup;
1515

1616
final class StoreDocumentBench extends BaseBench
1717
{
18-
/** @Warmup(2) */
18+
#[Warmup(2)]
1919
public function benchStoreDocument(): void
2020
{
2121
$user = new User();
@@ -27,7 +27,7 @@ public function benchStoreDocument(): void
2727
$this->getDocumentManager()->clear();
2828
}
2929

30-
/** @Warmup(2) */
30+
#[Warmup(2)]
3131
public function benchStoreDocumentWithEmbedOne(): void
3232
{
3333
$address = new Address();
@@ -44,7 +44,7 @@ public function benchStoreDocumentWithEmbedOne(): void
4444
$this->getDocumentManager()->clear();
4545
}
4646

47-
/** @Warmup(2) */
47+
#[Warmup(2)]
4848
public function benchStoreDocumentWithEmbedMany(): void
4949
{
5050
$user = new User();
@@ -58,7 +58,7 @@ public function benchStoreDocumentWithEmbedMany(): void
5858
$this->getDocumentManager()->clear();
5959
}
6060

61-
/** @Warmup(2) */
61+
#[Warmup(2)]
6262
public function benchStoreDocumentWithReferenceOne(): void
6363
{
6464
$account = new Account();
@@ -74,7 +74,7 @@ public function benchStoreDocumentWithReferenceOne(): void
7474
$this->getDocumentManager()->clear();
7575
}
7676

77-
/** @Warmup(2) */
77+
#[Warmup(2)]
7878
public function benchStoreDocumentWithReferenceMany(): void
7979
{
8080
$group1 = new Group('One');

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"doctrine/coding-standard": "^14.0",
4949
"doctrine/orm": "^3.2",
5050
"jmikola/geojson": "^1.0",
51-
"phpbench/phpbench": "^1.0.0",
51+
"phpbench/phpbench": "^1.4.0",
5252
"phpstan/phpstan": "^2.1",
5353
"phpstan/phpstan-deprecation-rules": "^2.0",
5454
"phpstan/phpstan-phpunit": "^2.0",

0 commit comments

Comments
 (0)