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
$ python -m timeit -s "v = 'foo'" "v == 'foo' or v == 'bar'" | |
10000000 loops, best of 3: 0.163 usec per loop | |
$ python -m timeit -s "v = 'bar'" "v == 'foo' or v == 'bar'" | |
1000000 loops, best of 3: 0.233 usec per loop | |
$ python -m timeit -s "v = 'baz'" "v == 'foo' or v == 'bar'" | |
1000000 loops, best of 3: 0.241 usec per loop | |
$ python -m timeit -s "v = 'foo'" "v in ('foo', 'bar')" | |
10000000 loops, best of 3: 0.145 usec per loop | |
$ python -m timeit -s "v = 'bar'" "v in ('foo', 'bar')" | |
10000000 loops, best of 3: 0.155 usec 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
$ python -m timeit -s 'seq = list(range(10))' '[o for o in seq]' | |
1000000 loops, best of 3: 1.75 usec per loop | |
$ python -m timeit -s 'seq = list(range(100))' '[o for o in seq]' | |
100000 loops, best of 3: 13.2 usec per loop | |
$ python -m timeit -s 'seq = list(range(1000))' '[o for o in seq]' | |
10000 loops, best of 3: 115 usec per loop | |
$ python -m timeit -s 'seq = list(range(10))' 'list(seq)' | |
1000000 loops, best of 3: 0.372 usec per loop | |
$ python -m timeit -s 'seq = list(range(100))' 'list(seq)' | |
1000000 loops, best of 3: 0.609 usec 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
$ python -m timeit -s "a, b, c, d, e, f = 'abcdef'" "any(v for v in (a, b, c, d, e, f) if v == '')" | |
1000000 loops, best of 3: 1.51 usec per loop | |
$ python -m timeit -s "a, b, c, d, e, f = 'abcdef'" "'' in (a, b, c, d, e, f)" | |
1000000 loops, best of 3: 0.36 usec per loop | |
$ python -m timeit -s "a, b, c, d, e, f = ' bcdef'" "any(v for v in (a, b, c, d, e, f) if v == '')" | |
1000000 loops, best of 3: 1.52 usec per loop | |
$ python -m timeit -s "a, b, c, d, e, f = ' bcdef'" "'' in (a, b, c, d, e, f)" | |
1000000 loops, best of 3: 0.354 usec per loop | |
$ python -m timeit -s "a, b, c, d, e, f = 'abcde '" "any(v for v in (a, b, c, d, e, f) if v == '')" | |
1000000 loops, best of 3: 1.49 usec 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
import io | |
import os | |
import tempfile | |
import timeit | |
# A valid PNG file. | |
png_bytes = ( | |
'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00\x01\x08' | |
'\x06\x00\x00\x00\x1f\x15\xc4\x89\x00\x00\x00\nIDATx\x9cc\x00\x01\x00\x00' |
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
$ python2.7 | |
Python 2.7.14 (default, Sep 22 2017, 00:06:07) | |
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)] on darwin | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> value = u'\u0141uk\u0105\u015b\u017a' | |
>>> '%s' % value | |
u'\u0141uk\u0105\u015b\u017a' | |
>>> '{}'.format(value) | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> |
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
(djangae) $ git log HEAD~1.. | |
commit 74bee22fc276276af6dc82db9dc6b933a0d2e6b0 (HEAD -> 958-computed-field-pagination, upstream/958-computed-field-pagination) | |
Author: Phil Tysoe | |
Date: Thu Nov 9 17:11:29 2017 +0000 | |
Fix 16 bit max signed int value | |
(djangae) $ ./runtests.sh | |
Not running install_deps. Pass --install_deps if you want to install dependencies. | |
Creating test database for alias 'default'... |
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
(djangae) $ git show | |
commit 0523c70eba0f7bc7b36933fbbf002e4611086720 (HEAD -> 958-computed-field-pagination, upstream/958-computed-field-pagination) | |
Merge: 010a6cd1 b96d2284 | |
Author: Phil Tysoe <[email protected]> | |
Date: Thu Nov 9 16:05:51 2017 +0000 | |
Merge branch 'master' into 958-computed-field-pagination | |
diff --cc CHANGELOG.md | |
index 4d961159,cb652b0c..0d7ae63e |
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
import itertools | |
def grouper(iterable, n): | |
"""Collect data into chunks. | |
This is different to the grouper recipe in itertools in that the final | |
chunk may be shorter. | |
>>> grouper('ABCDEF', 3) |
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 python2 | |
import csv | |
import hashlib | |
import sys | |
# Calculate an MD5 checksum for every row in the first column of a CSV. | |
# Example: | |
# $ python digests.py < src.csv > dest.csv |
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
# Speed comparison of bencodepy and buxtor.bencode | |
# bencodepy is consistently 0.3 - 0.5 seconds faster. Why? | |
# bencodepy: https://github.com/eweast/BencodePy/blob/master/bencodepy/encode.py | |
# 4914005 function calls (3618005 primitive calls) in 2.830 seconds | |
# | |
# | |
# buxtor.bencode: https://github.com/davidwtbuxton/buxtor/blob/master/buxtor/bencode.py | |
# 5592005 function calls (4548005 primitive calls) in 3.183 seconds |