1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
|
4
|
|
|
use Innmind\Immutable\Set; |
5
|
|
|
|
6
|
|
|
final class SetBench |
7
|
|
|
{ |
8
|
|
|
private $data; |
9
|
|
|
private $set; |
10
|
|
|
|
11
|
|
|
public function __construct() |
12
|
|
|
{ |
13
|
|
|
$this->data = unserialize(file_get_contents(__DIR__.'/fixtures.data')); |
14
|
|
|
$this->set = Set::of('int', ...$this->data); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public function benchNamedConstructor() |
18
|
|
|
{ |
19
|
|
|
Set::of('int', ...$this->data); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function benchIntersect() |
23
|
|
|
{ |
24
|
|
|
$this->set->intersect($this->set); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function benchContains() |
28
|
|
|
{ |
29
|
|
|
$this->set->contains(500); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function benchRemove() |
33
|
|
|
{ |
34
|
|
|
$this->set->remove(500); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function benchDiff() |
38
|
|
|
{ |
39
|
|
|
$this->set->diff($this->set); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function benchEquals() |
43
|
|
|
{ |
44
|
|
|
$this->set->equals($this->set); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function benchFilter() |
48
|
|
|
{ |
49
|
|
|
$this->set->filter(static function(int $i): bool { |
50
|
|
|
return $i % 2 === 0; |
51
|
|
|
}); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function benchForeach() |
55
|
|
|
{ |
56
|
|
|
$this->set->foreach(static function(int $i): void { |
|
|
|
|
57
|
|
|
// pass |
58
|
|
|
}); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function benchGroupBy() |
62
|
|
|
{ |
63
|
|
|
$this->set->groupBy(static function(int $i): int { |
64
|
|
|
return $i % 2; |
65
|
|
|
}); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function benchMap() |
69
|
|
|
{ |
70
|
|
|
$this->set->map(static function(int $i): int { |
71
|
|
|
return $i ** 2; |
72
|
|
|
}); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function benchPartition() |
76
|
|
|
{ |
77
|
|
|
$this->set->partition(static function(int $i): bool { |
78
|
|
|
return $i % 2 === 0; |
79
|
|
|
}); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function benchMerge() |
83
|
|
|
{ |
84
|
|
|
$this->set->merge($this->set); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function benchReduce() |
88
|
|
|
{ |
89
|
|
|
$this->set->reduce( |
90
|
|
|
0, |
91
|
|
|
static function(int $sum, int $i): int { |
92
|
|
|
return $sum + $i; |
93
|
|
|
} |
94
|
|
|
); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.