Skip to content

Commit 759b6c1

Browse files
committed
Add benchmark to convert BSON structures to PHP via iteration
1 parent 63da6c2 commit 759b6c1

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

benchmark/BSON/DocumentBench.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use MongoDB\BSON\Document;
77
use PhpBench\Attributes\BeforeMethods;
88

9+
use stdClass;
910
use function file_get_contents;
1011
use function iterator_to_array;
1112

@@ -49,6 +50,15 @@ public function benchToPHPObject(): void
4950
self::$document->toPHP();
5051
}
5152

53+
public function benchToPHPObjectViaIteration(): void
54+
{
55+
$object = new stdClass();
56+
57+
foreach (self::$document as $key => $value) {
58+
$object->$key = $value;
59+
}
60+
}
61+
5262
public function benchToPHPArray(): void
5363
{
5464
self::$document->toPHP(['root' => 'array']);

benchmark/BSON/PackedArrayBench.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ public function benchToPHPArray(): void
5555
self::$array->toPHP();
5656
}
5757

58+
public function benchToPHPArrayViaIteration(): void
59+
{
60+
$array = [];
61+
62+
foreach (self::$array as $key => $value) {
63+
$array[$key] = $value;
64+
}
65+
}
66+
5867
public function benchIteration(): void
5968
{
6069
// phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedForeach

0 commit comments

Comments
 (0)