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

Less type hints #111

Closed marc-mabe closed 5 years ago

marc-mabe commented 5 years ago

Removed type-hints (except void) for private and final methods as this gives a small performance boost and this lib has enough tests to make sure it's working as expected.

Benchmark result:

+----------------+------------------------------+--------+--------+------+----------------+-------------------------+
| benchmark      | subject                      | groups | params | revs | tag:MAJOR:mean | tag:lessTypeHints_:mean |
+----------------+------------------------------+--------+--------+------+----------------+-------------------------+
| EnumSet66Bench | benchAttachEnumeratorOnEmpty |        | []     | 2000 | 30.783μs       | 28.493μs                |
| EnumSet66Bench | benchAttachValueOnEmpty      |        | []     | 2000 | 56.411μs       | 53.703μs                |
| EnumSet66Bench | benchAttachEnumeratorOnFull  |        | []     | 2000 | 30.597μs       | 28.442μs                |
| EnumSet66Bench | benchAttachValueOnFull       |        | []     | 2000 | 56.412μs       | 53.715μs                |
| EnumSet66Bench | benchDetachEnumeratorOnEmpty |        | []     | 2000 | 31.284μs       | 28.958μs                |
| EnumSet66Bench | benchDetachValueOnEmpty      |        | []     | 2000 | 57.008μs       | 54.199μs                |
| EnumSet66Bench | benchDetachEnumeratorOnFull  |        | []     | 2000 | 31.423μs       | 28.897μs                |
| EnumSet66Bench | benchDetachValueOnFull       |        | []     | 2000 | 56.693μs       | 54.084μs                |
| EnumSet66Bench | benchContainsEnumeratorTrue  |        | []     | 2000 | 29.876μs       | 26.986μs                |
| EnumSet66Bench | benchContainsValueTrue       |        | []     | 2000 | 53.853μs       | 51.888μs                |
| EnumSet66Bench | benchContainsEnumeratorFalse |        | []     | 2000 | 29.974μs       | 27.004μs                |
| EnumSet66Bench | benchContainsValueFalse      |        | []     | 2000 | 53.815μs       | 51.934μs                |
| EnumSet66Bench | benchIterateFull             |        | []     | 2000 | 35.096μs       | 35.396μs                |
| EnumSet66Bench | benchIterateEmpty            |        | []     | 2000 | 0.571μs        | 0.570μs                 |
| EnumSet66Bench | benchCountFull               |        | []     | 2000 | 1.424μs        | 1.419μs                 |
| EnumSet66Bench | benchCountEmpty              |        | []     | 2000 | 0.333μs        | 0.327μs                 |
| EnumSet66Bench | benchIsEqual                 |        | []     | 2000 | 0.121μs        | 0.121μs                 |
| EnumSet66Bench | benchIsSubset                |        | []     | 2000 | 0.121μs        | 0.122μs                 |
| EnumSet66Bench | benchIsSuperset              |        | []     | 2000 | 0.169μs        | 0.169μs                 |
| EnumSet66Bench | benchUnion                   |        | []     | 2000 | 0.235μs        | 0.234μs                 |
| EnumSet66Bench | benchIntersect               |        | []     | 2000 | 0.232μs        | 0.233μs                 |
| EnumSet66Bench | benchDiff                    |        | []     | 2000 | 0.252μs        | 0.253μs                 |
| EnumSet66Bench | benchSymDiff                 |        | []     | 2000 | 0.237μs        | 0.232μs                 |
| EnumSet66Bench | benchGetOrdinalsFull         |        | []     | 2000 | 3.244μs        | 3.225μs                 |
| EnumSet66Bench | benchGetOrdinalsEmpty        |        | []     | 2000 | 0.341μs        | 0.332μs                 |
| EnumSet66Bench | benchGetValues               |        | []     | 2000 | 31.070μs       | 30.359μs                |
| EnumSet66Bench | benchGetNames                |        | []     | 2000 | 34.719μs       | 33.899μs                |
| EnumSet66Bench | benchGetEnumerators          |        | []     | 2000 | 29.518μs       | 28.905μs                |
| EnumBench      | benchGetName                 |        | []     | 2500 | 4.936μs        | 4.672μs                 |
| EnumBench      | benchGetValue                |        | []     | 2500 | 2.230μs        | 2.225μs                 |
| EnumBench      | benchGetOrdinal              |        | []     | 2500 | 3.117μs        | 2.903μs                 |
| EnumBench      | benchIsByEnumerator          |        | []     | 2500 | 3.636μs        | 3.248μs                 |
| EnumBench      | benchIsByValue               |        | []     | 2500 | 5.654μs        | 5.317μs                 |
| EnumBench      | benchDetectConstants         |        | []     | 2500 | 62.596μs       | 62.511μs                |
| EnumBench      | benchGetValues               |        | []     | 2500 | 0.351μs        | 0.337μs                 |
| EnumBench      | benchGetNames                |        | []     | 2500 | 0.112μs        | 0.109μs                 |
| EnumBench      | benchGetOrdinals             |        | []     | 2500 | 0.375μs        | 0.361μs                 |
| EnumBench      | benchGetEnumerators          |        | []     | 2500 | 10.420μs       | 9.803μs                 |
| EnumBench      | benchByValue                 |        | []     | 2500 | 28.026μs       | 27.307μs                |
| EnumBench      | benchByValueAndInstantiate   |        | []     | 2500 | 43.467μs       | 42.259μs                |
| EnumBench      | benchByName                  |        | []     | 2500 | 9.103μs        | 8.594μs                 |
| EnumBench      | benchByNameAndInstantiate    |        | []     | 2500 | 46.501μs       | 44.991μs                |
| EnumBench      | benchByOrdinal               |        | []     | 2500 | 19.382μs       | 19.006μs                |
| EnumBench      | benchByOrdinalAndInstantiate |        | []     | 2500 | 32.429μs       | 31.050μs                |
| EnumBench      | benchGetByValues             |        | []     | 2500 | 31.381μs       | 30.165μs                |
| EnumBench      | benchGetByEnumerator         |        | []     | 2500 | 5.023μs        | 4.228μs                 |
| EnumBench      | benchGetByCallStatic         |        | []     | 2500 | 17.351μs       | 16.075μs                |
| EnumBench      | benchHasByEnumerator         |        | []     | 2500 | 4.769μs        | 4.381μs                 |
| EnumBench      | benchHasByValue              |        | []     | 2500 | 21.991μs       | 20.526μs                |
| EnumSet32Bench | benchAttachEnumerator        |        | []     | 2000 | 10.654μs       | 10.038μs                |
| EnumSet32Bench | benchAttachValue             |        | []     | 2000 | 20.892μs       | 20.133μs                |
| EnumSet32Bench | benchDetachEnumerator        |        | []     | 2000 | 10.599μs       | 9.874μs                 |
| EnumSet32Bench | benchDetachValue             |        | []     | 2000 | 20.963μs       | 20.021μs                |
| EnumSet32Bench | benchContainsEnumeratorTrue  |        | []     | 2000 | 11.757μs       | 10.581μs                |
| EnumSet32Bench | benchContainsEnumeratorFalse |        | []     | 2000 | 11.735μs       | 10.622μs                |
| EnumSet32Bench | benchContainsValueTrue       |        | []     | 2000 | 21.382μs       | 20.333μs                |
| EnumSet32Bench | benchContainsValueFalse      |        | []     | 2000 | 21.378μs       | 20.285μs                |
| EnumSet32Bench | benchIterateFull             |        | []     | 2000 | 15.943μs       | 15.688μs                |
| EnumSet32Bench | benchIterateEmpty            |        | []     | 2000 | 0.819μs        | 0.822μs                 |
| EnumSet32Bench | benchCountFull               |        | []     | 2000 | 0.615μs        | 0.608μs                 |
| EnumSet32Bench | benchCountEmpty              |        | []     | 2000 | 0.173μs        | 0.168μs                 |
| EnumSet32Bench | benchIsEqual                 |        | []     | 2000 | 0.146μs        | 0.146μs                 |
| EnumSet32Bench | benchIsSubset                |        | []     | 2000 | 0.146μs        | 0.147μs                 |
| EnumSet32Bench | benchIsSuperset              |        | []     | 2000 | 0.138μs        | 0.137μs                 |
| EnumSet32Bench | benchUnion                   |        | []     | 2000 | 0.200μs        | 0.200μs                 |
| EnumSet32Bench | benchIntersect               |        | []     | 2000 | 0.202μs        | 0.202μs                 |
| EnumSet32Bench | benchDiff                    |        | []     | 2000 | 0.202μs        | 0.202μs                 |
| EnumSet32Bench | benchSymDiff                 |        | []     | 2000 | 0.200μs        | 0.200μs                 |
| EnumSet32Bench | benchGetOrdinalsFull         |        | []     | 2000 | 1.130μs        | 1.104μs                 |
| EnumSet32Bench | benchGetOrdinalsEmpty        |        | []     | 2000 | 0.618μs        | 0.616μs                 |
| EnumSet32Bench | benchGetValues               |        | []     | 2000 | 14.744μs       | 14.449μs                |
| EnumSet32Bench | benchGetNames                |        | []     | 2000 | 16.518μs       | 16.075μs                |
| EnumSet32Bench | benchGetEnumerators          |        | []     | 2000 | 13.943μs       | 13.628μs                |
| EnumMapBench   | benchGetKeysEmpty            |        | []     | 2000 | 0.331μs        | 0.332μs                 |
| EnumMapBench   | benchGetKeysFull             |        | []     | 2000 | 20.713μs       | 20.154μs                |
| EnumMapBench   | benchGetValuesEmpty          |        | []     | 2000 | 0.069μs        | 0.071μs                 |
| EnumMapBench   | benchGetValuesFull           |        | []     | 2000 | 0.092μs        | 0.074μs                 |
| EnumMapBench   | benchSearchTypeJuggling      |        | []     | 2000 | 1.423μs        | 1.392μs                 |
| EnumMapBench   | benchSearchStrict            |        | []     | 2000 | 0.631μs        | 0.609μs                 |
| EnumMapBench   | benchOffsetSetEnumerator     |        | []     | 2000 | 19.698μs       | 18.527μs                |
| EnumMapBench   | benchOffsetSetValue          |        | []     | 2000 | 46.751μs       | 45.645μs                |
| EnumMapBench   | benchOffsetUnsetEnumerator   |        | []     | 2000 | 18.228μs       | 17.429μs                |
| EnumMapBench   | benchOffsetUnsetValue        |        | []     | 2000 | 45.000μs       | 43.630μs                |
| EnumMapBench   | benchOffsetExistsEnumerator  |        | []     | 2000 | 18.429μs       | 17.240μs                |
| EnumMapBench   | benchOffsetExistsValue       |        | []     | 2000 | 43.898μs       | 42.337μs                |
| EnumMapBench   | benchContainsEnumerator      |        | []     | 2000 | 19.135μs       | 17.688μs                |
| EnumMapBench   | benchContainsValue           |        | []     | 2000 | 45.518μs       | 44.062μs                |
| EnumMapBench   | benchIterateFull             |        | []     | 2000 | 51.135μs       | 51.590μs                |
| EnumMapBench   | benchIterateEmpty            |        | []     | 2000 | 0.194μs        | 0.193μs                 |
| EnumMapBench   | benchCountFull               |        | []     | 2000 | 0.063μs        | 0.063μs                 |
| EnumMapBench   | benchCountEmpty              |        | []     | 2000 | 0.061μs        | 0.061μs                 |
| EnumBench      | benchGetConstants            |        | []     | 2500 |                | 0.117μs                 |
+----------------+------------------------------+--------+--------+------+----------------+-------------------------+
prolic commented 5 years ago

I don't like this idea. The performance difference is only marginal. I'm okay with removing for private methods, but not for the public API.

marc-mabe commented 5 years ago

Yes I didn't decide yet - just want to see the difference. I'll also make a bench with only internal methods (private and final) only for comparison

marc-mabe commented 5 years ago

updated to remove type-hints (except void) for private and final methods only. I have updated the PR description and bench -> the bench result looks still very close the the previous result.