|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
|
|
4
|
|
|
use Innmind\Immutable\Sequence; |
|
5
|
|
|
|
|
6
|
|
|
final class SequenceBench |
|
7
|
|
|
{ |
|
8
|
|
|
private $data; |
|
9
|
|
|
private $sequence; |
|
10
|
|
|
|
|
11
|
|
|
public function __construct() |
|
12
|
|
|
{ |
|
13
|
|
|
$this->data = unserialize(file_get_contents(__DIR__.'/fixtures.data')); |
|
14
|
|
|
$this->sequence = new Sequence(...$this->data); |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
public function benchNamedConstructor() |
|
18
|
|
|
{ |
|
19
|
|
|
Sequence::of(...$this->data); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function benchMap() |
|
23
|
|
|
{ |
|
24
|
|
|
$this->sequence->map(static function(int $i): int { |
|
25
|
|
|
return $i ** 2; |
|
26
|
|
|
}); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function benchGet() |
|
30
|
|
|
{ |
|
31
|
|
|
$this->sequence->get(500); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function benchHas() |
|
35
|
|
|
{ |
|
36
|
|
|
$this->sequence->has(500); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function benchIndexOf() |
|
40
|
|
|
{ |
|
41
|
|
|
$this->sequence->indexOf(500); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function benchDistinct() |
|
45
|
|
|
{ |
|
46
|
|
|
$this->sequence->indexOf(500); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function benchDiff() |
|
50
|
|
|
{ |
|
51
|
|
|
$this->sequence->diff($this->sequence); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function benchAppend() |
|
55
|
|
|
{ |
|
56
|
|
|
$this->sequence->append($this->sequence); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function benchContains() |
|
60
|
|
|
{ |
|
61
|
|
|
$this->sequence->contains(500); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function benchDrop() |
|
65
|
|
|
{ |
|
66
|
|
|
$this->sequence->drop(500); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function benchDropEnd() |
|
70
|
|
|
{ |
|
71
|
|
|
$this->sequence->dropEnd(500); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function benchEquals() |
|
75
|
|
|
{ |
|
76
|
|
|
$this->sequence->equals($this->sequence); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function benchFilter() |
|
80
|
|
|
{ |
|
81
|
|
|
$this->sequence->filter(static function(int $i): bool { |
|
82
|
|
|
return $i % 2 === 0; |
|
83
|
|
|
}); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function benchForeach() |
|
87
|
|
|
{ |
|
88
|
|
|
$this->sequence->foreach(static function(int $i): void { |
|
89
|
|
|
// pass |
|
90
|
|
|
}); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function benchGroupBy() |
|
94
|
|
|
{ |
|
95
|
|
|
$this->sequence->groupBy(static function(int $i): int { |
|
96
|
|
|
return $i % 2; |
|
97
|
|
|
}); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public function benchFirst() |
|
101
|
|
|
{ |
|
102
|
|
|
$this->sequence->first(); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public function benchLast() |
|
106
|
|
|
{ |
|
107
|
|
|
$this->sequence->last(); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function benchIndices() |
|
111
|
|
|
{ |
|
112
|
|
|
$this->sequence->indices(); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
public function benchTake() |
|
116
|
|
|
{ |
|
117
|
|
|
$this->sequence->take(500); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
public function benchTakeEnd() |
|
121
|
|
|
{ |
|
122
|
|
|
$this->sequence->takeEnd(500); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
public function benchIntersect() |
|
126
|
|
|
{ |
|
127
|
|
|
$this->sequence->intersect($this->sequence); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
public function benchSort() |
|
131
|
|
|
{ |
|
132
|
|
|
$this->sequence->sort(static function(): int { |
|
133
|
|
|
return -1; |
|
134
|
|
|
}); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
public function benchReduce() |
|
138
|
|
|
{ |
|
139
|
|
|
$this->sequence->reduce( |
|
140
|
|
|
0, |
|
141
|
|
|
static function(int $sum, int $i): int { |
|
142
|
|
|
return $sum + $i; |
|
143
|
|
|
} |
|
144
|
|
|
); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
public function benchReverse() |
|
148
|
|
|
{ |
|
149
|
|
|
$this->sequence->reverse(); |
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
|