（1) comparison of performance between pypy and Cpython interpreters
CpythonThe interpreter is downloaded from the official website Python’s own interpreter, which is the interpreter we usually use. The emergence of the pypy interpreter is to improve the efficiency of Python code operation to a certain extent. According to statistics, the efficiency of the pypy interpreter running the same code is about Cpython.6 times.
1. pypyInstallation test
1 # install 2 apt-get install pypy 3 # test 4 pypy
Enter pypy on the command line and enter the interface similar to python.
2. Performance comparison
Talk is cheap, show my code. Use the following code to see the difference in efficiency between the two.
1 import time 2 3 start = time.time() 4 for i in range(10000*10000): 5 i +=1 6 end = time.time() 7 8 print('time used:%f'%(end-start))
The operation of using pypy interpreter is very simple. You only need to add pypy before the.Py file. The execution of the two interpreters of the above code is as follows:
There is wood in the sky. The reason why pypy execution time is so short is to exchange space for time.
But don’t be too happy! Pypy, since the efficiency is so high, why is it not popular? The reason is that pypy does not support as many libraries as Cpython does, and many third party libraries such as pandas do not support pypy.
So, do not want to wait too long for a small partner, if you want to use pypy, then we must do a good job of using internal library building code to prepare! Cool!
The mass processing of text processing class recommends the use of pypy!
（Two) iterative / cyclic progress bar
Some partners are not unwilling to wait too long, but want to know how long they will have to wait. Write a circle to run and run there. I don’t know where to run.
The next one is the high forcing artifact, a third party library tqdm, which is specially designed to solve this problem.
1 pip install tqdm
1 from tqdm import tqdm 2 import time 3 4 for i in tqdm(range(1000)): 5 time.sleep(0.01)
Look at the effect of dazzle
1 #encoding:utf-8 2 3 import sys 4 5 print "Script name:", sys.argv 6 for i in range(1, len(sys.argv)): 7 print "parameter", i, sys.argv[i]
The results are as follows:
argv[i]It is used to read the parameters of the command line input!