I ran the below two code snippets through profilers and it turned out Sample 2 consumes a bit less memory and ran a bit faster. My intuition is the compiler should optimize