一亿条数据查找一百万条数据
直接上代码
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
如果觉得对您有帮助,麻烦您点一下推荐,谢谢!
好记忆不如烂笔头
好记忆不如烂笔头

浙公网安备 33010602011771号