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
"Performance test comparing string slice to buffer() and memoryview()." | |
import os | |
import timeit | |
TESTDATA = os.urandom(16 * 1000) | |
def test_control(s=TESTDATA): | |
"Use a slice to access a substring of s" | |
t = s[2:-1] | |
return len(t) |
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
[aliles@macbookpro ~]$ time python2.7 timeit_tco.py 40000 | |
Computed number of length 166714 | |
1.014175 seconds on CPU | |
real 0m2.109s | |
user 0m2.094s | |
sys 0m0.013s | |
[aliles@macbookpro ~]$ time pypy timeit_tco.py 40000 | |
Computed number of length 166714 |
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
[aliles@macbookpro ~]$ time python2.7 timeit_tco.py 100 60000 | |
Maximum time on CPU: 0.00030600 | |
Minimum time on CPU: 0.00014800 | |
Average time on CPU: 0.00015401 | |
real 0m9.586s | |
user 0m9.473s | |
sys 0m0.110s | |
[aliles@macbookpro ~]$ time pypy timeit_tco.py 100 60000 |
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
import main | |
if main.executed(): | |
print 'Hello World' |
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
"One time dictionary class" | |
from functools import partial, wraps as full_wrap | |
__all__ = ['OneTimeDict'] | |
wraps = partial(full_wrap, assigned=('__name__', '__doc__')) | |
class OneTimeDict(dict): | |
"""One time dictionary object. |
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
"Benchmark decompression performance" | |
from collections import namedtuple | |
import argparse | |
import bz2 | |
import functools | |
import gzip | |
import hashlib | |
import itertools | |
import logging | |
import sys |
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
"Simple command line parsing using argparse." | |
from collections import namedtuple | |
from functools import partial | |
import argparse | |
__all__ = ['Argument', 'parse_cmdline'] | |
class Argument(namedtuple('BaseArgument', 'short full default help')): | |
"""Command line argument option for command line parser. | |
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
from main import execute | |
@execute | |
def main(): | |
do_something() | |
def do_something(): | |
print "Hello World" |
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
"Logistic map iteration timing" | |
from itertools import islice | |
import time | |
import main | |
def logistic_map(r, x): | |
assert r > 0, 'R must be a positive number' | |
assert 0 < x < 1, 'X must be a number between 0 and 1' | |
while True: |
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
import sys | |
import time | |
from avro_geonames import * | |
if __name__ == '__main__': | |
iterator = iter_geonames(sys.argv[1]) | |
writer = open_writer() | |
start = time.clock() | |
for n in xrange(100000): |
OlderNewer