#!/usr/bin/env python

import utils, sys

def strip_brackets(string):
    d = 0
    out = ''
    for c in string:
        if c == '{' or c == '[': d += 1

        if d > 0:
            out += ' '
        else:
            out += c

        if c == '}' or c == ']': d -= 1

    return out

for f in sys.argv[1:]:
    t = utils.benchmark(lambda: utils.with_utf8_file(f, strip_brackets))
    sys.stderr.write('{0}: {1}\n'.format(f, t))
Exemplo n.º 2
0
#!/usr/bin/env python

import utils, sys

def sort(string):
    lines = string.splitlines()
    lines.sort()
    return '\n'.join(lines)

for f in sys.argv[1:]:
    t = utils.benchmark(lambda: sys.stdout.write(
                    				utils.with_utf8_file(f,sort).encode('utf-8'))
                    				)
    sys.stderr.write('{0}: {1}\n'.format(f, t))

Exemplo n.º 3
0
#!/usr/bin/env python

import utils, sys

for f in sys.argv[1:]:
    t = utils.benchmark(lambda: utils.with_utf8_file(f, lambda c: len(c)))
    sys.stderr.write('{0}: {1}\n'.format(f, t))
Exemplo n.º 4
0
#!/usr/bin/env python

import utils, sys

def word_count(string):
    freqs = {}
    for w in string.split():
        w = w.lower()
        if freqs.get(w):
            freqs[w] += 1
        else:
            freqs[w] = 1
    return freqs

for f in sys.argv[1:]:
    t = utils.benchmark(lambda: utils.with_utf8_file(f, word_count))
    sys.stderr.write('{0}: {1}\n'.format(f, t))
Exemplo n.º 5
0
#!/usr/bin/env python

import utils, sys

for f in sys.argv[1:]:
    t = utils.benchmark(lambda: utils.with_utf8_file(f, lambda c: c.upper()))
    sys.stderr.write('{0}: {1}\n'.format(f, t))
Exemplo n.º 6
0
#!/usr/bin/env python

import utils, sys

def sort(string):
    lines = string.split('\n')
    lines.sort()
    return '\n'.join(lines)

for f in sys.argv[1:]:
    t = utils.benchmark(lambda:
            utils.with_utf8_file(f, lambda c:
                    sys.stdout.write(sort(c).encode('utf-8'))))
    sys.stderr.write('{0}: {1}\n'.format(f, t))