In this challenge, we are using Visual Basic for Applications (VBA) to automate code so that Steve can research the stock market for his parents. They are interested in renewable energy and want to invest in companies that build green energy systems and components. Steve wants us to create code that, when run, will give him the total daily volume and annual return of the green energy companies. We will be refactoring code to loop through all given data and determining if refactoring makes the code more efficient.
In the original code, running code for 2017 took approximately 0.523 seconds.
For 2018, it took about 0.531 seconds to run.
After refactoring and adding a total of three output arrays, the code ran more effeciently than the original code. When running the refactored code for 2017, it took approximately 0.082 seconds.
Running the refactored code for 2018 0.078 seconds.
As shown by the images above, refactoring code can substantially increase runtime efficiency while being executed. Looping code saves time because writing individual code for every variable separately would be extremely time consuming. Refactoring code can also be easier to debug. One disadvantage of refactoring is that it can not improve underlying code building issues. This can be an issue when the programming language becomes dated. Another disadvantage to refactoring code is that it can potentially introduce bugs that take time to find and fix.