Repository navigation
Expand file tree
/
Copy pathFileCacheStorageBench.php
More file actions
92 lines (75 loc) · 2.42 KB
/
Copy pathFileCacheStorageBench.php
File metadata and controls
92 lines (75 loc) · 2.42 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php declare(strict_types = 1);
namespace PHPStan\Benchmark;
use LogicException;
use PHPStan\Cache\FileCacheStorage;
use PHPStan\Internal\DirectoryCreatorException;
use Tally\Attribute\Before;
use Tally\Attribute\DataProvider;
use Tally\Attribute\ExpectedFor;
use Tally\ScratchDirectory;
final class FileCacheStorageBench
{
private ?FileCacheStorage $storage = null;
/** @var list<array{string, int, list<string>}> */
private array $data = [];
public function __construct(private ScratchDirectory $scratch)
{
}
/**
* @return iterable<string, array{int}>
*/
public static function entries(): iterable
{
foreach ([100, 10000] as $entries) {
yield 'entries-' . $entries => [$entries];
}
}
/**
* @throws DirectoryCreatorException
*/
#[Before]
public function boot(int $entries): void
{
BenchContainer::create($this->scratch);
$this->storage = new FileCacheStorage($this->scratch->path() . '/file-cache-bench');
// the counted calls do not autoload
$this->storage->save('warmup', 'v1', self::data(2));
$this->storage->load('warmup', 'v1');
$this->data = self::data($entries);
$this->storage->save('load-' . $entries, 'v1', $this->data);
}
/**
* @throws DirectoryCreatorException
*/
#[DataProvider(method: 'entries')]
#[ExpectedFor(dataSet: 'entries-100', instructions: '246.5K', cycles: '582.7K', memory: '17.29KiB')]
#[ExpectedFor(dataSet: 'entries-10000', instructions: '18.84M', cycles: '29.57M', memory: '1.345MiB')]
public function benchSave(int $entries): void
{
if ($this->storage === null) {
throw new LogicException('boot() did not run.');
}
$this->storage->save('save-' . $entries, 'v1', $this->data);
}
#[DataProvider(method: 'entries')]
#[ExpectedFor(dataSet: 'entries-100', instructions: '388.9K', cycles: '763.4K', memory: '130.1KiB')]
#[ExpectedFor(dataSet: 'entries-10000', instructions: '37.00M', cycles: '70.18M', memory: '11.67MiB')]
public function benchLoad(int $entries): mixed
{
if ($this->storage === null) {
throw new LogicException('boot() did not run.');
}
return $this->storage->load('load-' . $entries, 'v1');
}
/**
* @return list<array{string, int, list<string>}> shaped like the cached PHPDoc and reflection data
*/
private static function data(int $entries): array
{
$data = [];
for ($i = 0; $i < $entries; $i++) {
$data[] = ['App\\Model\\Entity' . $i, $i, ['int', 'string|null', 'list<App\\Model\\Entity' . $i . '>']];
}
return $data;
}
}