update from atlas
This commit is contained in:
18
02-array-seq/listcomp_speed.py
Normal file
18
02-array-seq/listcomp_speed.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import timeit
|
||||
|
||||
TIMES = 10000
|
||||
|
||||
SETUP = """
|
||||
symbols = '$¢£¥€¤'
|
||||
def non_ascii(c):
|
||||
return c > 127
|
||||
"""
|
||||
|
||||
def clock(label, cmd):
|
||||
res = timeit.repeat(cmd, setup=SETUP, number=TIMES)
|
||||
print(label, *('{:.3f}'.format(x) for x in res))
|
||||
|
||||
clock('listcomp :', '[ord(s) for s in symbols if ord(s) > 127]')
|
||||
clock('listcomp + func :', '[ord(s) for s in symbols if non_ascii(ord(s))]')
|
||||
clock('filter + lambda :', 'list(filter(lambda c: c > 127, map(ord, symbols)))')
|
||||
clock('filter + func :', 'list(filter(non_ascii, map(ord, symbols)))')
|
||||
Reference in New Issue
Block a user