GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — fluentpython-example-code/02-array-seq/listcomp_speed.py at master · slee124565/fluentpython-example-code Expand file tree/ Copy pathlistcomp_speed.pyMore file actions 18 lines (14 loc) · 545 Bytes / Copy pathlistcomp_speed.pyFile metadata and controls18 lines (14 loc) · 545 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 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)))') |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |