Python的dict类型迭代性能的优化(items()与iteritems()、keys()与iterkeys()、values()与itervalues()的区别)
来源:互联网 发布:淘宝助理怎样删除宝贝 编辑:程序博客网 时间:2024/06/06 02:15
#coding=utf-8'''演示dict的items()与iteritems()的区别从演示结果可以看出iteritems()对于大的dict性能方面是有很大的提升的拥有10**4个item的dict就应该使用iteritems(),而不是items()。同理对keys()、iterkeys()、values()、itervalues()也是适用的'''import timeif __name__=='__main__':# n个数量级,如果你电脑性能足够好,完全可以把n值设置得更大些n = 8width = 16align = '<'print "{0:{align}{width}}{1:{align}{width}}{2:{align}{width}}".format('', 'items()', 'iteritems()', width=width, align=align)for i in range(n):tDict = {}.fromkeys(range(10**i))# normal,使用itemsnStart = time.time()for j in tDict.items():passnEnd = time.time()# iter,使用iteritemsiStart = time.time()for j in tDict.iteritems():passiEnd = time.time()print "{0:{align}{width}}{1:{align}{width}.4f}{2:{align}{width}.4f}".format(i, nEnd-nStart, iEnd-iStart, width=width, align=align)
- Python的dict类型迭代性能的优化(items()与iteritems()、keys()与iterkeys()、values()与itervalues()的区别)
- Python与QueryDirets directory items(), keys(), values()
- dict里面的itervalues() 方法比 values()
- Python的字典的items(), keys(), values(),时间类型处理
- Python的字典的items(), keys(), values()
- Python的字典的items(), keys(), values()
- Python的字典的items(), keys(), values()
- Python的字典的items(), keys(), values()
- dict的items函数和iteritems函数
- Python中 dict.items() dict.iteritems()区别
- Python中 dict.items() dict.iteritems()区别
- Python中 dict.items() dict.iteritems()区别
- python中values、keys、items与*arg,**arg
- items( ) 与 iteritems()
- python 字典访问 items()和iteritems()的区别
- python字典中items()和iteritems()的区别
- 今天开始学Python(dictionary的keys,values,items函数)
- python中字典keys,values,items的使用
- 松本行弘:我的编程人生
- java permgen space outOFMemory 总结
- android 学习知识点累计
- 信号安全跟线程安全函数背后本质
- java环境变量引起的编译错误(包括package等的说明)
- Python的dict类型迭代性能的优化(items()与iteritems()、keys()与iterkeys()、values()与itervalues()的区别)
- JNI 安装 Cygwin, nDK
- java读取文件propeties...
- 在苹果lion中安装xcode3系列版本
- Windows Vista/7中关机、睡眠和休眠的区别
- 为什么页面接收到的中文是乱码?
- MacOS下卸载XCode的命令
- Win7下,Office 2010和Adobe Acrobat Professional 8.1不兼容:PDFMaker文件遗失
- 虚假排名