Py优化技巧

1.函数返回值缓存 可以把一个非常耗时的函数调用变成O(1)时间复杂度 适用于在处理固定参数的函数被重复调用时 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

Py性能分析示例

1.time.time() 简单的计时器 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #!/usr/bin/python import time def timefunc(f): def f_timer(*args, **kwargs): start = time.time() result = f(*args, **kwargs) end = time.time() print f.__name__, 'took', end - start, 'time' return result return f_timer @timefunc def test(): for i in xrange(100): print i test() 2.time

Python高阶函数

python高阶函数 1.map map(function, iterable) The map() function takes the form map(function, iterable) and applies function to each item in iterable to return a list in Python 2 or an iterable map object in Python 3, 将iterable中的每个元素作用与funciton

dogpile cache总结

1.介绍 dogpile是python缓存的开源库,openstack项目在使用 官方文档 https://dogpilecache.sqlalchemy.org/en/latest/ dogpile provides the concept of a “dogpile lock”, a control structure which allows a

Python常用库

Python常用库 • atexit allows you to register functions for your program to call when it exits. 在程序的任何地方都可以注册一个或多个回调函数,在程序退出时执行 • argparse provides functions for parsing command line arguments. 解析命令行参