I am currently in a personal learning project where I read in an XML database. I find myself writing functions that gather data and I’m not sure what would be a fast way to return them.
Which is generally faster:
yields, or- several
append()s within the function thenreturnthe ensuinglist?
I would be happy to know in what situations where yields would be faster than append()s or vice-versa.
yieldhas the huge advantage of being lazy and speed is usually not the best reason to use it. But if it works in your context, then there is no reason not to use it:This is the result:
At least in this very simple test,
yieldis faster than append.