GCI22 - Avoid to use methods for basic operation
收藏资源简介:
Description This repository contains an empirical analysis on the energy consumption impact of the Creedengo rule GCI82. This rule recommends avoiding the use of methods for simple operations. In the Python language used here, this means preferring operators such as + instead of functions like .__add__(), and also avoiding the creation of methods such as add when they only perform a simple addition. The purpose of this analysis is therefore to evaluate whether applying this rule has a measurable impact on energy consumption. Methodology Two versions of the Python programs were developed: the first containing the code smell, where simple operations are performed through dedicated methods or special function calls, the second version following the rule recommendation, where direct operators such as + are preferred instead of methods like .__add__() or unnecessary wrapper functions. To collect energy measurements, the energyTracer tool was used. Analysis 2 996 612 samples collected with the code smell 2 998 521 samples collected without the code smell Significance level: α = 0.05 Metric Δ mean p-value Cohen's d effect Significant cpu_mj +57.05% 0.00e+00 +102.552 very large ✅ gpu_mj +55.69% 0.00e+00 +21.791 large ✅ dram_mj +55.13% 0.00e+00 +5.167 large ✅ time_s +54.91% 0.00e+00 +78.352 very large ✅ Δ mean = (mean_with − mean_without) / mean_with × 100. A positive value means the smell consumes more energy. Conclusion The rule appears to show a noticeable impact when the code smell is repeated a large number of times. However, the relevance of the rule can still be questioned, since the likelihood of this rule actually being triggered in a programmer’s code is relatively low. Even for beginners, it is quite uncommon to write code containing this kind of code smell. In conclusion, the rule may not be as relevant as it initially seems.



