I'm using python in my research, but when the data is in GB, the calculation doesn't finish easily. So, using something called pypy with a JIT compiler I thought I'd finish it quickly! !! When I wrote the code in the same way, the calculation part was certainly very fast, but I don't think it's too fast to write files using the csv module ... When I wondered why, the pypy page said something like this
Missing RPython modules: A few modules of the standard library (like csv and cPickle) are written in C in CPython, but written natively in pure Python in PyPy. Sometimes the JIT is able to do a good job on them, and sometimes not. In most cases (like csv and cPickle), we're slower than CPython, with the notable exception of json and heapq.
http://pypy.org/performance.html
Are you serious. I used python on the spot, but it's still slow with python ...
I was wondering how slow pypy is, which is said to be slow by the official, so I experimented this time.
That is this
test.py
#coding:utf-8
import csv
import time
start = time.clock()
test_sentence = ["which","is","faster","Python","or","Pypy","?"]
iter_list = [100,1000,10000,100000,1000000,2000000,5000000,10000000]
time_list = []
with open("fast_writing.csv","wb")as f:
writer = csv.writer(f)
for i in iter_list:
loop_start = time.clock()
for j in xrange(i):
writer.writerow(test_sentence)
end_time = time.clock() -loop_start
time_list.append(end_time)
end_loop = time.clock() - start
time_list.append(end_loop)
print "The time it took{0}".format(end_loop)
with open("pythonresult.csv","wb")as f:
writer= csv.writer(f)
writer.writerow(time_list)
As the number of times increases, pypy is getting faster. Certainly python seems to be faster if writing about 10,000 times
Does it depend on the conditions? You don't really see the effect in such a salty experiment.
However, as the number of writes increases, pypy is faster. Pypy seems to work better when processing large matrices. It seems that pypy also has numpy, so if it is matrix processing, it would be better to use pypy for high-speed processing. However, there are some points to be aware of when using pypy, and if neglected, the processing time will be unnecessarily long, so be careful.
Recommended Posts