Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@internetimagery
Created May 25, 2021 09:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save internetimagery/a7c20be22dd98a6906b4dff71531f7e8 to your computer and use it in GitHub Desktop.
Save internetimagery/a7c20be22dd98a6906b4dff71531f7e8 to your computer and use it in GitHub Desktop.
Testing tee efficiency against list
from itertools import tee
from time import time
def t1(count):
l = []
for i in range(count):
l.append(i)
def t2(count):
a, b = tee(range(count))
for _ in a:
pass
count = 1000
for i in range(5):
now = time()
t1(count)
time1 = time() - now
now = time()
t2(count)
time2 = time() - now
print(count, time1, time2)
count *= 10
# 1000 6.842613220214844e-05 3.4809112548828125e-05
# 10000 0.0011477470397949219 0.000476837158203125
# 100000 0.006156206130981445 0.004708051681518555
# 1000000 0.06155204772949219 0.05104660987854004
# 10000000 0.5977113246917725 0.6441948413848877
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment