Commit 82ec4ac
committed
__callStatic: cache created Enum instances
Instead of creating a new one each time, cache them.
This only matters if you're creating thousands of these objects.
I've used a small test script:
<?
require './vendor/autoload.php';
class Fast extends MyCLabs\Enum\Enum {
protected const VALUE_ONE = "one";
protected const VALUE_TWO = "two";
}
$t = microtime(true);
for ($i = 0; $i < 1000; $i++) {
Fast::VALUE_ONE();
}
$secondsPerOp = (microtime(true) - $t) / 1000;
var_dump("Microseconds per op: " . $secondsPerOp * 1000000);
Before this change, we were getting about 4us per operation,
after this, we get about 1us per op, a 4X speedup!!
Note: This only matters if you end up constrcuting thousands of these
objects. We end up using this library extensively and thus end up
incurring more than ten milliseconds per request just for Enum
construction.1 parent a1fd916 commit 82ec4ac
1 file changed
+16
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
40 | 48 | | |
41 | 49 | | |
42 | 50 | | |
| |||
211 | 219 | | |
212 | 220 | | |
213 | 221 | | |
214 | | - | |
215 | 222 | | |
216 | 223 | | |
217 | 224 | | |
218 | 225 | | |
219 | | - | |
220 | | - | |
221 | | - | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
222 | 233 | | |
223 | | - | |
224 | | - | |
| 234 | + | |
225 | 235 | | |
226 | 236 | | |
227 | 237 | | |
| |||
0 commit comments