I have been doing a lot of work on the Gate
class lately. While adding some new features and fixing a bug, I came across something interesting.
When defining Gates, you can set the ability to either a closure or a string using the '@' notation to reference a class method. If you use a closure, it will add it directly to the abilities
property. If you use the '@' notation, it will resolve the method and add that resulting closure to the abilities
property.
This got me thinking about whether it was more efficient (memory and speed) to resolve the string when defining the abilities and storing the closure on the property, or storing the string on the abilities
property and resolving it only when actually called.
A priori, it seems reasonable that the closures are going to be more memory intensive than the strings. Regarding speed, I had no idea if there would be a significant difference either way.
I created the memory.php
and speed.php
poorman's benchmarks to try testing this. From the results of these scripts, it appears that the 'String' option is much better in terms of memory, and that there is no discernable difference between the two in regards to speed.
I'll be the first to admit I'm out of my element on this benchmarking, so I was hoping for some feedback on this before submitting a PR. If I'm way off base please let me know, or if there are some improvements I could make to measure the memory or speed it would be much appreciated!