In [1]:
import timeit

In [7]:
TIMES = 100000
SETUP = """
symbols = '$¢£¥€¤'
def non_ascii(c):
    return c > 127
"""

In [8]:
def clock(label, cmd):
    res = timeit.repeat(cmd, setup=SETUP, number=TIMES)
    print(label, *(f'{x:.2f}' for x in res))

In [9]:
clock("listcomp\t:", '[ord(s) for s in symbols if ord(s) > 127]')
clock("listcomp + func\t:", '[ord(s) for s in symbols if non_ascii(ord(s))]')
clock("filter + lambda\t:", 'list(filter(lambda c: c > 127, map(ord, symbols)))')
clock("filter + func\t:", 'list(filter(non_ascii, map(ord, symbols)))')


listcomp	: 0.09 0.08 0.08
listcomp + func	: 0.12 0.12 0.12
filter + lambda	: 0.12 0.11 0.12
filter + func	: 0.11 0.11 0.12

In [ ]: