python3中的dict循环性能对比
生活随笔
收集整理的這篇文章主要介紹了
python3中的dict循环性能对比
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
情況一、遍歷key
import timeitDATA_SIZE = 10**6 testDict = dict() for i in range(DICT_SIZE):testDict[i] = i # 構建大小為100W的字典def test1():for _ in testDict.keys():passdef test2():for _ in testDict:passdef test3():for _,m in testDict.items():pass二、遍歷values
import timeitDATA_SIZE = 10**6 testDict = dict() for i in range(DICT_SIZE):testDict[i] = i # 構建大小為100W的字典def test1():for k in testDict.keys():ss = testDict[k]def test2():for k in testDict:ss = testDict[k]def test3():for k, v in testDict.items():ss = v三、結論:
總結
以上是生活随笔為你收集整理的python3中的dict循环性能对比的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python 多进程中锁的使用方法
- 下一篇: dict()与{},list()与[]性