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

Refactor EnumMap - fixes #91 #92

Closed marc-mabe closed 7 years ago

marc-mabe commented 7 years ago

fixes #91

marc-mabe commented 7 years ago

@prolic As you can see the changes will make it a but slower - If you have a another idea how to fix this and how to make EnumMap more useful please tell me. Also I have no idea why benchOffsetSet* take so much more memory. Any ideas?

Refactor EnumMap
+--------------+-----------------------------+--------+--------+------+-----+------------+----------+----------+----------+----------+---------+--------+-------------+
| benchmark    | subject                     | groups | params | revs | its | mem_peak   | best     | mean     | mode     | worst    | stdev   | rstdev | diff        |
+--------------+-----------------------------+--------+--------+------+-----+------------+----------+----------+----------+----------+---------+--------+-------------+
| EnumMapBench | benchOffsetSetEnumerator    |        | []     | 2000 | 25  | 9,444,832b | 30.711μs | 32.141μs | 31.849μs | 33.115μs | 0.586μs | 1.82%  | +27,337.85% |
| EnumMapBench | benchOffsetSetValue         |        | []     | 2000 | 25  | 9,444,824b | 60.976μs | 63.697μs | 64.582μs | 65.572μs | 1.463μs | 2.30%  | +54,276.49% |
| EnumMapBench | benchOffsetUnsetEnumerator  |        | []     | 2000 | 25  | 1,051,992b | 27.154μs | 28.501μs | 29.049μs | 29.677μs | 0.833μs | 2.92%  | +24,230.53% |
| EnumMapBench | benchOffsetUnsetValue       |        | []     | 2000 | 25  | 1,051,984b | 60.296μs | 62.053μs | 61.178μs | 64.671μs | 1.243μs | 2.00%  | +52,873.48% |
| EnumMapBench | benchOffsetExistsEnumerator |        | []     | 2000 | 25  | 1,043,800b | 24.916μs | 25.716μs | 25.816μs | 26.915μs | 0.546μs | 2.12%  | +21,853.27% |
| EnumMapBench | benchOffsetExistsValue      |        | []     | 2000 | 25  | 1,043,792b | 56.051μs | 57.610μs | 58.133μs | 58.935μs | 0.812μs | 1.41%  | +49,080.59% |
| EnumMapBench | benchIterateFull            |        | []     | 2000 | 25  | 1,043,936b | 65.970μs | 67.654μs | 68.043μs | 69.161μs | 0.773μs | 1.14%  | +57,654.55% |
| EnumMapBench | benchIterateEmpty           |        | []     | 2000 | 25  | 1,043,880b | 0.282μs  | 0.290μs  | 0.286μs  | 0.304μs  | 0.006μs | 2.12%  | +147.48%    |
| EnumMapBench | benchCountFull              |        | []     | 2000 | 25  | 1,043,784b | 0.116μs  | 0.117μs  | 0.117μs  | 0.122μs  | 0.002μs | 1.28%  | +0.12%      |
| EnumMapBench | benchCountEmpty             |        | []     | 2000 | 25  | 1,043,784b | 0.116μs  | 0.117μs  | 0.117μs  | 0.123μs  | 0.001μs | 1.09%  | 0.00%       |
+--------------+-----------------------------+--------+--------+------+-----+------------+----------+----------+----------+----------+---------+--------+-------------+

Master:
+--------------+-----------------------------+--------+--------+------+-----+------------+----------+----------+----------+----------+---------+--------+-------------+
| benchmark    | subject                     | groups | params | revs | its |  mem_peak  | best     | mean     | mode     | worst    | stdev   | rstdev | diff        |
+--------------+-----------------------------+--------+--------+------+-----+------------+----------+----------+----------+----------+---------+--------+-------------+
| EnumMapBench | benchOffsetSetEnumerator    |        | []     | 2000 | 25  |   992,712b | 26.868μs | 28.207μs | 28.236μs | 28.888μs | 0.437μs | 1.55%  | +36,437.77% |
| EnumMapBench | benchOffsetSetValue         |        | []     | 2000 | 25  |   992,704b | 59.006μs | 60.665μs | 60.384μs | 63.055μs | 1.059μs | 1.75%  | +78,481.32% |
| EnumMapBench | benchOffsetUnsetEnumerator  |        | []     | 2000 | 25  |   992,712b | 24.410μs | 25.391μs | 25.833μs | 26.086μs | 0.586μs | 2.31%  | +32,789.51% |
| EnumMapBench | benchOffsetUnsetValue       |        | []     | 2000 | 25  |   992,704b | 55.667μs | 57.148μs | 57.411μs | 58.981μs | 0.971μs | 1.70%  | +73,925.44% |
| EnumMapBench | benchOffsetExistsEnumerator |        | []     | 2000 | 25  |   992,712b | 25.768μs | 26.755μs | 26.539μs | 28.059μs | 0.758μs | 2.83%  | +34,556.30% |
| EnumMapBench | benchOffsetExistsValue      |        | []     | 2000 | 25  |   992,712b | 57.592μs | 60.003μs | 60.163μs | 61.914μs | 1.013μs | 1.69%  | +77,624.02% |
| EnumMapBench | benchIterateFull            |        | []     | 2000 | 25  |   992,704b | 25.190μs | 25.727μs | 25.483μs | 26.629μs | 0.445μs | 1.73%  | +33,225.08% |
| EnumMapBench | benchIterateEmpty           |        | []     | 2000 | 25  |   992,704b | 0.222μs  | 0.226μs  | 0.227μs  | 0.231μs  | 0.002μs | 1.07%  | +192.69%    |
| EnumMapBench | benchCountFull              |        | []     | 2000 | 25  |   992,696b | 0.074μs  | 0.077μs  | 0.077μs  | 0.081μs  | 0.001μs | 1.65%  | +0.05%      |
| EnumMapBench | benchCountEmpty             |        | []     | 2000 | 25  |   992,696b | 0.075μs  | 0.077μs  | 0.077μs  | 0.080μs  | 0.001μs | 1.62%  | 0.00%       |
+--------------+-----------------------------+--------+--------+------+-----+------------+----------+----------+----------+----------+---------+--------+-------------+
prolic commented 7 years ago

@marc-mabe Let me check this weekend. I am very busy these days.

marc-mabe commented 7 years ago

Yea - no problem - thanks

prolic commented 7 years ago

Looks good to me. About the benchOffsetSet*-methods: I have no idea why this is taking so much memory. You could debug with memory_get_usage all over the code, maybe you'll find something.