-
-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathMetadataBench.php
More file actions
69 lines (61 loc) · 1.85 KB
/
MetadataBench.php
File metadata and controls
69 lines (61 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
declare(strict_types=1);
namespace Yiisoft\Queue\Tests\Benchmark;
use Generator;
use PhpBench\Attributes\ParamProviders;
use Yiisoft\Queue\Message\IdEnvelope;
use Yiisoft\Queue\Message\Message;
use Yiisoft\Queue\Message\MessageInterface;
use Yiisoft\Queue\Middleware\FailureHandling\FailureEnvelope;
final class MetadataBench
{
/**
* Create metadata as an array and read its value from an array.
*/
public function benchArrayRead(): void
{
$message = new Message('foo', 'bar', ['id' => 1]);
$id = $message->getMetadata()['id'];
}
/**
* Create metadata as an object and read its value immediately.
*/
public function benchEnvelopeRead(): void
{
$message = new IdEnvelope(new Message('foo', 'bar'), 1);
$id = $message->getId();
}
public function provideEnvelopeStackCounts(): Generator
{
yield 'one' => [1];
yield 'three' => [3];
yield 'fifteen' => [15];
}
/**
* Create envelope stack with the given depth
*
* @psalm-param array{0: int} $params
*/
#[ParamProviders('provideEnvelopeStackCounts')]
public function benchEnvelopeStackCreation(array $params): void
{
$message = new Message('foo', 'bar');
for ($i = 0; $i < $params[0]; $i++) {
$message = new FailureEnvelope($message, ["fail$i" => "fail$i"]);
}
}
/**
* Create a metadata array with the given elements count
*
* @psalm-param array{0: int} $params
*/
#[ParamProviders('provideEnvelopeStackCounts')]
public function benchMetadataArrayCreation(array $params): void
{
$metadata = ['failure-meta' => []];
for ($i = 0; $i < $params[0]; $i++) {
$metadata['failure-meta']["fail$i"] = "fail$i";
}
$message = new Message('foo', 'bar', $metadata);
}
}