一亿条数据查找一百万条数据

直接上代码

复制代码
import time


def spider():
    start_time = time.time()
    data_dict = {}
    for page in range(100000000):
        data_dict[str(page)] = '1'
    print("haoshi_1:",time.time()-start_time)
    print(len(data_dict))
    print("haoshi_2:", time.time() - start_time)
    count = 0
    for page in range(1000000):
        if data_dict.get(str(page)):
            count = count + 1
    print("count",count)
    print("haoshi_3:", time.time() - start_time)

if __name__ == '__main__':
    spider()
复制代码

 

输出结果:

 

haoshi_1: 48.03097939491272
100000000
haoshi_2: 48.03097939491272
count 1000000
haoshi_3: 48.42287993431091

 

posted @   淋哥  阅读(3)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示