%load_ext autoreload
%autoreload 2
from itertools import chain
from utils import prof
def perf(func, *args, **kwargs):
return prof(func, locals(), globals(), *args, **kwargs)
results = tuple((i, i + 10) for i in range (1000, 120000))
passage = list(range(500, 15000))
def highlights1():
hl = set()
for r in results:
for n in r:
if n in passage:
hl.add(n)
return hl
def highlights2():
passageSet = set(passage)
hl = set()
for r in results:
for n in r:
if n in passageSet:
hl.add(n)
return hl
def highlights3():
passageSet = set(passage)
resultSet = set(chain.from_iterable(results))
return resultSet & passageSet
def highlights4():
passageSet = set(passage)
return {n for n in chain.from_iterable(results) if n in passageSet}
def highlights5():
passageSet = set(passage)
resultSet = set(chain.from_iterable(results))
return passageSet & resultSet
def highlights6():
return set(passage) & set(chain.from_iterable(results))
def highlights7():
hl = set(chain.from_iterable(results))
hl &= set(passage)
return hl
def highlights8():
hl = set(passage)
hl &= set(chain.from_iterable(results))
return hl
x = perf(highlights1)
len(x)
27992 function calls in 34.633 seconds Ordered by: cumulative time ncalls tottime percall cumtime percall filename:lineno(function) 1 34.630 34.630 34.633 34.633 <ipython-input-56-6396d786dd5a>:1(highlights1) 27990 0.003 0.000 0.003 0.000 {method 'add' of 'set' objects} 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
14000
x = perf(highlights2)
len(x)
27992 function calls in 0.022 seconds Ordered by: cumulative time ncalls tottime percall cumtime percall filename:lineno(function) 1 0.020 0.020 0.022 0.022 <ipython-input-95-88cb43bc4e71>:1(highlights2) 27990 0.002 0.000 0.002 0.000 {method 'add' of 'set' objects} 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
14000
x = perf(highlights3)
len(x)
3 function calls in 0.012 seconds Ordered by: cumulative time ncalls tottime percall cumtime percall filename:lineno(function) 1 0.012 0.012 0.012 0.012 <ipython-input-96-b09acc5de287>:1(highlights3) 1 0.000 0.000 0.000 0.000 {built-in method from_iterable} 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
14000
x = perf(highlights4)
len(x)
4 function calls in 0.018 seconds Ordered by: cumulative time ncalls tottime percall cumtime percall filename:lineno(function) 1 0.000 0.000 0.018 0.018 <ipython-input-97-eee82afdc6f2>:1(highlights4) 1 0.017 0.017 0.017 0.017 <ipython-input-97-eee82afdc6f2>:3(<setcomp>) 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects} 1 0.000 0.000 0.000 0.000 {built-in method from_iterable}
14000
x = perf(highlights5)
len(x)
3 function calls in 0.012 seconds Ordered by: cumulative time ncalls tottime percall cumtime percall filename:lineno(function) 1 0.012 0.012 0.012 0.012 <ipython-input-98-21e6f1772e41>:1(highlights5) 1 0.000 0.000 0.000 0.000 {built-in method from_iterable} 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
14000
x = perf(highlights6)
len(x)
3 function calls in 0.013 seconds Ordered by: cumulative time ncalls tottime percall cumtime percall filename:lineno(function) 1 0.013 0.013 0.013 0.013 <ipython-input-99-22b2aab4f7ce>:1(highlights6) 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects} 1 0.000 0.000 0.000 0.000 {built-in method from_iterable}
14000
x = perf(highlights7)
len(x)
3 function calls in 0.014 seconds Ordered by: cumulative time ncalls tottime percall cumtime percall filename:lineno(function) 1 0.014 0.014 0.014 0.014 <ipython-input-100-ce6127a37f64>:1(highlights7) 1 0.000 0.000 0.000 0.000 {built-in method from_iterable} 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
14000