File write speed comparison experiment between python 2.7.9 and pypy 2.5.0

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)

スクリーンショット 2015-02-20 1.03.12.png

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

File write speed comparison experiment between python 2.7.9 and pypy 2.5.0
Speed comparison between CPython and PyPy
File open function in Python3 (difference between open and codecs.open and speed comparison)
Write O_SYNC file in C and Python
Create new file [Comparison between Bash and PowerShell]
Speed comparison between incrementing count variable and enumerate
[Ruby vs Python] Benchmark comparison between Rails and Flask
[Ubuntu] [Python] Face detection comparison between dlib and OpenCV
datetime and file write and backup
Read and write csv file
Read and write a file
Write and read a file
Python 3 sorted and comparison functions
[Python] How to set variable names dynamically and speed comparison
AtCoder ABC151 Problem D Speed comparison in C ++ / Python / PyPy
Difference between Ruby and Python split
Difference between java and python (memo)
Difference between list () and [] in Python
Speed comparison of Wiktionary full text processing with F # and Python
Difference between == and is in python
[Python] Write to csv file with Python
Cooperation between python module and API
Difference in how to write if statement between ruby ​​and python
Differences between Python, stftime and strptime
Difference between python2 series and python3 series dict.keys ()
Python CSV file reading and writing
Python memo ① Folder and file operations
Python executable file conversion module comparison 2
Speed comparison of Python XML parsing
[Python] Difference between function and method
Summary of differences between Python and PHP (comparison table of main items)
Python --Difference between exec and eval
[Python] Difference between randrange () and randint ()
[Python] Difference between sorted and sorted (Colaboratory)
Write a C language linked list in an object-oriented style (with code comparison between Python and Java)
Communicate between Elixir and Python with gRPC
Differences in authenticity between Python and JavaScript
Differences between Ruby and Python in scope
difference between statements (statements) and expressions (expressions) in Python
Differences in syntax between Python and Java
Difference between PHP and Python finally and exit
Difference between @classmethod and @staticmethod in Python
Copy file and rewrite cell value @python
Difference between append and + = in Python list
Difference between nonlocal and global in Python
[Python] Difference between class method and static method
Exclusive file access between processes in Python
Difference between docker-compose env_file and .env file
Read and write JSON files in Python
See file and folder information on python
[Python3] Switch between Shift_JIS, UTF-8 and ASCII
[Python Iroha] Difference between List and Tuple
[python] Difference between rand and randn output
speed difference between wsgi, Bottle and Flask
Compress python data and write to sqlite
Differences in multithreading between Python and Jython
Differences between Ruby and Python (basic syntax)
[python] Read html file and practice scraping
Correspondence between Python built-in functions and Rust
Speed comparison of murmurhash3, md5 and sha1
Exchange encrypted data between Python and C #