Conclusion

Approach #3 is a whopping 134 times faster than approach #1.

While the time difference in our scenario was only 4 seconds, it could be hours for millions of records.

This demonstrates how important refactoring is to the development process. Refactoring your code furthers your understanding of the technologies you work with. It also illustrates how important it is to minimize the SQL queries performed within your web application. If this was an action initiated by the user, the difference in the request time would be 4.02 seeconds vs. 30 ms.