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

EnumMap IteratorAggregate using Generator #113

Closed marc-mabe closed 5 years ago

marc-mabe commented 5 years ago

(similar to #110)

This gives a nice good performance improvement not only on iterating an EnumMap and reduces complexity. It also makes the iterator immutable due to changes happening to a map on iterating.

But the following BC breaks will happen:

Bench:

+--------------+-----------------------------+--------+--------+------+----------------+--------------------+
| benchmark    | subject                     | groups | params | revs | tag:4.x:mean   | tag:generator:mean |
+--------------+-----------------------------+--------+--------+------+----------------+--------------------+
| EnumMapBench | benchGetKeysEmpty           |        | []     | 2000 | 0.339μs        | 0.348μs            |
| EnumMapBench | benchGetKeysFull            |        | []     | 2000 | 19.542μs       | 19.875μs           |
| EnumMapBench | benchGetValuesEmpty         |        | []     | 2000 | 0.069μs        | 0.069μs            |
| EnumMapBench | benchGetValuesFull          |        | []     | 2000 | 0.073μs        | 0.072μs            |
| EnumMapBench | benchSearchTypeJuggling     |        | []     | 2000 | 1.393μs        | 1.396μs            |
| EnumMapBench | benchSearchStrict           |        | []     | 2000 | 0.596μs        | 0.595μs            |
| EnumMapBench | benchOffsetSetEnumerator    |        | []     | 2000 | 18.454μs       | 16.123μs           |
| EnumMapBench | benchOffsetSetValue         |        | []     | 2000 | 44.485μs       | 41.045μs           |
| EnumMapBench | benchOffsetUnsetEnumerator  |        | []     | 2000 | 16.805μs       | 16.715μs           |
| EnumMapBench | benchOffsetUnsetValue       |        | []     | 2000 | 42.035μs       | 41.196μs           |
| EnumMapBench | benchOffsetExistsEnumerator |        | []     | 2000 | 16.373μs       | 16.304μs           |
| EnumMapBench | benchOffsetExistsValue      |        | []     | 2000 | 41.441μs       | 41.417μs           |
| EnumMapBench | benchContainsEnumerator     |        | []     | 2000 | 17.204μs       | 16.681μs           |
| EnumMapBench | benchContainsValue          |        | []     | 2000 | 43.013μs       | 42.603μs           |
| EnumMapBench | benchIterateFull            |        | []     | 2000 | 48.067μs       | 30.821μs           |
| EnumMapBench | benchIterateEmpty           |        | []     | 2000 | 0.195μs        | 0.252μs            |
| EnumMapBench | benchCountFull              |        | []     | 2000 | 0.063μs        | 0.063μs            |
| EnumMapBench | benchCountEmpty             |        | []     | 2000 | 0.061μs        | 0.061μs            |
+--------------+-----------------------------+--------+--------+------+----------------+--------------------+

@prolic ping