Last active
August 29, 2015 14:06
-
-
Save mambocab/c045539492f91853a29b to your computer and use it in GitHub Desktop.
iteration speed tests
This file contains hidden or 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
❯ ./speedtest.sh | |
2 ** 10 items | |
2 slices: 10000 loops, best of 3: 106 usec per loop | |
0 slices: 10000 loops, best of 3: 151 usec per loop | |
2 ** 15 items | |
2 slices: 100 loops, best of 3: 4.23 msec per loop | |
0 slices: 100 loops, best of 3: 5.68 msec per loop |
This file contains hidden or 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
❯ ./speedtest.sh | |
2 ** 10 items | |
2 slices: 10000 loops, best of 3: 109 usec per loop | |
0 slices: 10000 loops, best of 3: 123 usec per loop | |
2 ** 15 items | |
2 slices: 100 loops, best of 3: 4.48 msec per loop | |
0 slices: 100 loops, best of 3: 5.2 msec per loop |
This file contains hidden or 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
from __future__ import print_function | |
def pairs_2(xs): | |
for p in zip(xs[:-1], xs[1:]): | |
yield p | |
def pairs_0(lst): | |
last = object() | |
dummy = last | |
for x in lst: | |
if last is not dummy: | |
yield last,x | |
last = x | |
d = {2: pairs_2, 0: pairs_0} | |
def test(i, n, w): | |
r = range(2 ** n) | |
if w is list: | |
r = list(r) | |
big_list = list(d[i](r)) |
This file contains hidden or 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
#!/usr/bin/env bash | |
echo '2 ** 10 items' | |
echo -n '2 slices: ' | |
python -m timeit -s'import speedtest' 'speedtest.test(2, 10, None)' | |
echo -n '0 slices: ' | |
python -m timeit -s'import speedtest' 'speedtest.test(0, 10, None)' | |
echo | |
echo '2 ** 15 items' | |
echo -n '2 slices: ' | |
python -m timeit -s'import speedtest' 'speedtest.test(2, 15, None)' | |
echo -n '0 slices: ' | |
python -m timeit -s'import speedtest' 'speedtest.test(0, 15, None)' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment