Richard Quinn
1 min readAug 16, 2020

--

In your scenario 2, you instantiate the generator but you never use it.

This is why the time difference is so great. In Scenario 1 "return cubes" is called, and the entire list is walked. In scenario 2 you don't actually use "for val in getcubes(1000000)".

Just compare the "cubes" object in both scenarios, one is very large, the other is empty.

--

--

Richard Quinn
Richard Quinn

Written by Richard Quinn

I am a software engineering manager with over 25 years of experience. I am working to improve people’s health. Based in Basel, Switzerland.

No responses yet