Created
August 15, 2017 14:39
-
-
Save MSeifert04/f692b641076d92c5aa3d6ef4b06de39f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def double_evens1(inp): | |
for item in inp: | |
if not item % 2: | |
yield item | |
yield item | |
def double_evens2(inp): | |
for item in inp: | |
if not item % 2: | |
yield item | |
yield item | |
else: | |
yield item | |
for size in [10, 100, 1000, 10000, 100000]: | |
mylist = list(range(size)) | |
%timeit list(double_evens1(mylist)) | |
%timeit list(double_evens2(mylist)) | |
#9.76 µs ± 330 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each) | |
#9.24 µs ± 25.1 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each) | |
#59.3 µs ± 65.9 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each) | |
#59.5 µs ± 222 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each) | |
#536 µs ± 28.9 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each) | |
#637 µs ± 87.6 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each) | |
#5.22 ms ± 142 µs per loop (mean ± std. dev. of 7 runs, 100 loops each) | |
#5.2 ms ± 148 µs per loop (mean ± std. dev. of 7 runs, 100 loops each) | |
#54.5 ms ± 1.96 ms per loop (mean ± std. dev. of 7 runs, 10 loops each) | |
#53.6 ms ± 441 µs per loop (mean ± std. dev. of 7 runs, 10 loops each) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment