Benefits: Instead of using globals() and filtering the results, this imports the profiles in function and then uses locals(). This adds four benefits.
1: This can allow refreshing profiles in case of profile only updates or any other situation without restarting the application. This aspect is mainly beneficial for a GUI implementation.
2: This removes the need to use types.ModuleType just for a single conditional. While it isn't the main point, it resulted in roughly a 0.1-0.2 Mb decrease in RAM usage.
3: Removing the conditionals resulted in a roughly 5-10% performance improvement for the function.
4: In the rare case a global value has a property, method or attribute named "profile", the old version would give an error, this way it won't get the value at all let alone give an error.
Tests were measured using timeit comparing the old and new solutions running with numbers set to 1000000. So results are based on 1000000 times of the function being run.
Unit: seconds
Python version: 3.11.3
Old results:
70.173
71.835
70.173
New results:
64.133
64.187
64.165
*Edit: Performance numbers, after a reboot, they became much closer. Newer version is still faster even with the imports.
Benefits: Instead of using globals() and filtering the results, this imports the profiles in function and then uses locals(). This adds four benefits.
Tests were measured using timeit comparing the old and new solutions running with numbers set to 1000000. So results are based on 1000000 times of the function being run.
Unit: seconds Python version: 3.11.3 Old results:
New results:
*Edit: Performance numbers, after a reboot, they became much closer. Newer version is still faster even with the imports.