Skip to content

Commit e72b632

Browse files
committed
Disable Warmup and WriteConcern
1 parent 4560e67 commit e72b632

File tree

6 files changed

+49
-27
lines changed

6 files changed

+49
-27
lines changed

benchmark/BSON/DocumentBench.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
use MongoDB\Benchmark\BaseBench;
66
use MongoDB\BSON\Document;
77
use PhpBench\Attributes\BeforeMethods;
8+
use PhpBench\Attributes\Warmup;
89
use stdClass;
910

1011
use function file_get_contents;
1112
use function iterator_to_array;
1213

1314
#[BeforeMethods('prepareData')]
15+
#[Warmup(1)]
1416
final class DocumentBench extends BaseBench
1517
{
1618
private static Document $document;

benchmark/BSON/PackedArrayBench.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
use MongoDB\Benchmark\BaseBench;
66
use MongoDB\BSON\PackedArray;
77
use PhpBench\Attributes\BeforeMethods;
8+
use PhpBench\Attributes\Warmup;
89

910
use function array_values;
1011
use function iterator_to_array;
1112

1213
#[BeforeMethods('prepareData')]
14+
#[Warmup(1)]
1315
final class PackedArrayBench extends BaseBench
1416
{
1517
private static PackedArray $array;

benchmark/DriverBench/SingleDocBench.php

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@
66
use MongoDB\Benchmark\BaseBench;
77
use MongoDB\BSON\Document;
88
use MongoDB\Driver\Command;
9-
use PhpBench\Attributes as Bench;
9+
use MongoDB\Driver\WriteConcern;
10+
use PhpBench\Attributes\BeforeMethods;
11+
use PhpBench\Attributes\ParamProviders;
12+
use PhpBench\Attributes\Revs;
1013

1114
use function array_map;
1215
use function file_get_contents;
1316
use function range;
1417

1518
/** @see https://github.com/mongodb/specifications/blob/ddfc8b583d49aaf8c4c19fa01255afb66b36b92e/source/benchmarking/benchmarking.rst#single-doc-benchmarks */
16-
#[Bench\BeforeMethods('prepareDatabase')]
19+
#[BeforeMethods('prepareDatabase')]
1720
final class SingleDocBench extends BaseBench
1821
{
1922
public function prepareDatabase(): void
@@ -31,6 +34,22 @@ public function benchRunCommand(): void
3134
}
3235
}
3336

37+
/**
38+
* @see https://github.com/mongodb/specifications/blob/ddfc8b583d49aaf8c4c19fa01255afb66b36b92e/source/benchmarking/benchmarking.rst#find-one-by-id
39+
* @param array{options: array} $params
40+
*/
41+
#[BeforeMethods('setupFindOneById')]
42+
#[ParamProviders('provideFindOneByIdParams')]
43+
#[Revs(1)]
44+
public function benchFindOneById(array $params): void
45+
{
46+
$collection = self::getCollection();
47+
48+
for ($id = 1; $id <= 10_000; $id++) {
49+
$collection->findOne(['_id' => $id], $params['options']);
50+
}
51+
}
52+
3453
public function setupFindOneById(): void
3554
{
3655
$tweet = self::readJsonFile(self::TWEET_FILE_PATH);
@@ -50,18 +69,18 @@ public static function provideFindOneByIdParams(): Generator
5069
}
5170

5271
/**
53-
* @see https://github.com/mongodb/specifications/blob/ddfc8b583d49aaf8c4c19fa01255afb66b36b92e/source/benchmarking/benchmarking.rst#find-one-by-id
54-
* @param array{options: array} $params
72+
* @see https://github.com/mongodb/specifications/blob/ddfc8b583d49aaf8c4c19fa01255afb66b36b92e/source/benchmarking/benchmarking.rst#small-doc-insertone
73+
* @see https://github.com/mongodb/specifications/blob/ddfc8b583d49aaf8c4c19fa01255afb66b36b92e/source/benchmarking/benchmarking.rst#large-doc-bulk-insert
74+
* @param array{document: object|array, repeat: int, options?: array} $params
5575
*/
56-
#[Bench\BeforeMethods('setupFindOneById')]
57-
#[Bench\ParamProviders('provideFindOneByIdParams')]
58-
#[Bench\Revs(1)]
59-
public function benchFindOneById(array $params): void
76+
#[ParamProviders('provideInsertOneParams')]
77+
#[Revs(1)]
78+
public function benchInsertOne(array $params): void
6079
{
6180
$collection = self::getCollection();
6281

63-
for ($id = 1; $id <= 10_000; $id++) {
64-
$collection->findOne(['_id' => $id], $params['options']);
82+
for ($i = $params['repeat']; $i > 0; $i--) {
83+
$collection->insertOne($params['document'], $params['options'] ?? []);
6584
}
6685
}
6786

@@ -77,6 +96,12 @@ public static function provideInsertOneParams(): Generator
7796
'repeat' => 10_000,
7897
];
7998

99+
yield 'Small doc WC 0' => [
100+
'document' => self::readJsonFile(self::SMALL_FILE_PATH),
101+
'repeat' => 10_000,
102+
'options' => ['writeConcern' => new WriteConcern(0)],
103+
];
104+
80105
yield 'Large doc' => [
81106
'document' => self::readJsonFile(self::LARGE_FILE_PATH),
82107
'repeat' => 10,
@@ -86,21 +111,11 @@ public static function provideInsertOneParams(): Generator
86111
'document' => Document::fromJSON(file_get_contents(self::LARGE_FILE_PATH)),
87112
'repeat' => 10,
88113
];
89-
}
90-
91-
/**
92-
* @see https://github.com/mongodb/specifications/blob/ddfc8b583d49aaf8c4c19fa01255afb66b36b92e/source/benchmarking/benchmarking.rst#small-doc-insertone
93-
* @see https://github.com/mongodb/specifications/blob/ddfc8b583d49aaf8c4c19fa01255afb66b36b92e/source/benchmarking/benchmarking.rst#large-doc-bulk-insert
94-
* @param array{document: object|array, repeat: int} $params
95-
*/
96-
#[Bench\ParamProviders('provideInsertOneParams')]
97-
#[Bench\Revs(1)]
98-
public function benchInsertOne(array $params): void
99-
{
100-
$collection = self::getCollection();
101114

102-
for ($i = $params['repeat']; $i > 0; $i--) {
103-
$collection->insertOne($params['document']);
104-
}
115+
yield 'Large doc WC 0' => [
116+
'document' => Document::fromJSON(file_get_contents(self::LARGE_FILE_PATH)),
117+
'repeat' => 10,
118+
'options' => ['writeConcern' => new WriteConcern(0)],
119+
];
105120
}
106121
}

benchmark/ReadLargeDocumentBench.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use MongoDB\Model\BSONDocument;
1212
use PhpBench\Attributes\BeforeClassMethods;
1313
use PhpBench\Attributes\ParamProviders;
14+
use PhpBench\Attributes\Warmup;
1415

1516
use function array_fill;
1617
use function array_intersect_key;
@@ -24,6 +25,7 @@
2425
use const JSON_THROW_ON_ERROR;
2526

2627
#[BeforeClassMethods('prepareDatabase')]
28+
#[Warmup(1)]
2729
final class ReadLargeDocumentBench extends BaseBench
2830
{
2931
public static function prepareDatabase(): void

benchmark/ReadMultipleDocumentsBench.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use MongoDB\Model\BSONDocument;
1212
use PhpBench\Attributes\BeforeClassMethods;
1313
use PhpBench\Attributes\ParamProviders;
14+
use PhpBench\Attributes\Warmup;
1415

1516
use function array_fill;
1617
use function array_intersect_key;
@@ -20,6 +21,7 @@
2021
use function sprintf;
2122

2223
#[BeforeClassMethods('prepareDatabase')]
24+
#[Warmup(1)]
2325
final class ReadMultipleDocumentsBench extends BaseBench
2426
{
2527
public static function prepareDatabase(): void

phpbench.json.dist

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@
44
"runner.file_pattern": "*Bench.php",
55
"runner.path": "benchmark",
66
"runner.iterations": 3,
7-
"runner.revs": 10,
8-
"runner.warmup": 1
7+
"runner.revs": 10
98
}

0 commit comments

Comments
 (0)