Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Notebook Intel Atom 1.6 GHz:
- # CPython 2.7.5: 1.6 sec
- # PyPy 2.0.2: 0.6 sec
- def process():
- with open('src.csv') as f:
- content = f.readlines()
- D = {}
- for line in content:
- num, str = line.split(',', 1)
- D[num] = str
- maxLenght = max(len(key) for key in D.keys())
- ins = open('data.dat', 'r')
- r, counter = [], 0
- for line in ins:
- for j in range(maxLenght, 0, -1):
- # PyPy cannot optimize code with variable changing its type,
- # for example, if we uncomment these 2 lines
- # a = 'asdf'
- # a = 4
- # then PyPy speed will drop to CPython speed
- Tmp = D.get(line[:j], None)
- if Tmp is None: continue
- r.append(line[:-1] +' => '+Tmp)
- break
- ins.close()
- res_file = open('output2.txt', 'w')
- res_file.writelines(r)
- res_file.close()
- if __name__ == '__main__':
- from time import time
- t = time()
- process()
- print('time elapsed:', time()-t)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement