I have a relatively long (20,000 rows) CSV file and a simple function I wrote to open it:
def read_prices():
with open('sp500.csv', 'r') as f:
reader = csv.DictReader(f)
for row in reader:
yield float(row['Adj Close'].strip())
when I time it as it is it takes 3e-05s
:
print(timeit.timeit(lambda: read_prices(), number=100))
when I time the same function but with tuple(...)
it takes a whopping 27s
:
print(timeit.timeit(lambda: tuple(read_prices()), number=100))
Is this normal for tuple()
? Why might this be? I'm a beginner so ELI5 explanations welcome:)