marc-mabe / php-enum

Simple and fast implementation of enumerations with native PHP
BSD 3-Clause "New" or "Revised" License
464 stars 36 forks source link

Optimized EnumSet::count() and EnumSet::getOrdinals() #88

Closed marc-mabe closed 7 years ago

marc-mabe commented 7 years ago
$before:
+----------------+------------------+--------+--------+------+-----+------------+---------+---------+---------+---------+---------+--------+------------+
| benchmark      | subject          | groups | params | revs | its | mem_peak   | best    | mean    | mode    | worst   | stdev   | rstdev | diff       |
+----------------+------------------+--------+--------+------+-----+------------+---------+---------+---------+---------+---------+--------+------------+
| EnumSet66Bench | benchGetOrdinals |        | []     | 2000 | 25  | 1,094,776b | 7.078μs | 7.190μs | 7.133μs | 7.449μs | 0.099μs | 1.38%  | +1,409.27% |
| EnumSet32Bench | benchGetOrdinals |        | []     | 2000 | 25  | 1,032,616b | 3.251μs | 3.334μs | 3.318μs | 3.452μs | 0.047μs | 1.40%  | +599.78%   |
+----------------+------------------+--------+--------+------+-----+------------+---------+---------+---------+---------+---------+--------+------------+

$after:
+----------------+------------------+--------+--------+------+-----+------------+---------+---------+---------+---------+---------+--------+----------+
| benchmark      | subject          | groups | params | revs | its | mem_peak   | best    | mean    | mode    | worst   | stdev   | rstdev | diff     |
+----------------+------------------+--------+--------+------+-----+------------+---------+---------+---------+---------+---------+--------+----------+
| EnumSet66Bench | benchGetOrdinals |        | []     | 2000 | 25  | 1,094,856b | 4.286μs | 4.469μs | 4.507μs | 4.640μs | 0.098μs | 2.19%  | +842.34% |
| EnumSet32Bench | benchGetOrdinals |        | []     | 2000 | 25  | 1,032,696b | 2.059μs | 2.139μs | 2.160μs | 2.226μs | 0.048μs | 2.25%  | +350.96% |
+----------------+------------------+--------+--------+------+-----+------------+---------+---------+---------+---------+---------+--------+----------+