1. 程式人生 > >召喚小白鼠參與測試

召喚小白鼠參與測試

開發十年,就只剩下這套架構體系了! >>>   

import collections
import time

def gettf(x):
    res=dict()
    for t in x:
       res[t]=res.get(t,0)+1
    return res

with open('book.txt',"r",encoding='UTF-8') as f:
    text=f.read()

splitedText_list=text.split(' ')#list

time_start=time.time()
s=collections.Counter(splitedText_list)
time_end=time.time()
print('time cost',time_end-time_start,'s')

time_start=time.time()
s2=gettf(splitedText_list)
time_end=time.time()

print('time cost2',time_end-time_start,'s')
print(s["the"])
print(s2["the"])

我這裡測試