fork(1) download
  1. import timeit
  2.  
  3.  
  4. def m1():
  5. tdict = {}
  6. tstr = 'one two one two three'
  7. for w in tstr.split():
  8. tdict[w] = tdict.get(w, 0) + 1
  9. res = tdict[w] - 1
  10.  
  11.  
  12. def m2():
  13. tlist = []
  14. tstr = 'one two one two three'
  15. for w in tstr.split():
  16. res = tlist.count(w)
  17. tlist.append(w)
  18.  
  19.  
  20. print(timeit.timeit(m1, number=200000))
  21. print(timeit.timeit(m2, number=200000))
  22.  
Success #stdin #stdout 0.42s 9764KB
stdin
Standard input is empty
stdout
0.22107074409723282
0.18053963035345078