PyPyã®ã¤ã³ã¹ãã¼ã«
çããããã«ã¡ã¯
ãå
æ°ã§ãããTOEICçµãã£ã¦ç²ããã
æ¬æ¥ã¯PyPyã«ã¤ãã¦
What is PyPyï¼ãã¤ãã¤ï¼
Pythonã®å®è£
ã®ä¸ã¤ã§ãããã¾ã
ã»JIT ã³ã³ãã¤ã©ã§åãçºãé«éãCPythonã®ä»£ãããç®æãããã ã¨ããªãã¨ã
ã»RPythonã§æ¸ããã¦ããã¨ãï¼Wikipediaï¼
ã»è²ããªããã¸ã§ã¯ããèµ°ã£ã¦ããã¨ã
ã»å¤ã§è¿éã«è¨ãã¨ä¸å¯©è
ã«ééããããã¨ããããªãã¨ã
Install
brew install pypy
è¥ããã¯公式ホームページãããã¦ã³ãã¼ããã¦å±éãã¾ãããã
Numpyã®ã¤ã³ã¹ãã¼ã«
ä½ããå
¬å¼ã§ã¯ããã¤ãã®ããã¸ã§ã¯ãã§åéãéãã¦ããããã§ãã
numpyã¯ä»¥ä¸ã®ãããªæãã§ã¤ã³ã¹ãã¼ã«ã§ãã¾ãã
git clone https://bitbucket.org/pypy/numpy.git cd numpy pypy setup.py install
numpy ã®importã«å¤±æãã人ã¯ä»¥ä¸ã®ã³ãã³ããæã¡è¾¼ã¿ã¾ãããã
sudo pypy -c 'import numpy'
ãã£ãããªã®ã§é度ãæ¯è¼ãã¦ã¿ã
æ使ã£ãã³ã¼ãã使ãã¾ãããªãããªã¹ãã«å¯¾ãã¦ããããå¦çãå®è¡ãããã®ã§ãã
ã½ã¼ã¹ã³ã¼ã
import time Time = 10 N = 10000000 def list_append(): for i in xrange(Time): array = [] for j in xrange(N): array.append(1) def list_extend(): for i in xrange(Time): array = [] for j in xrange(N): array.extend([1]) def list_extend_list(): for i in xrange(Time): array = [] array.extend(range(N)) def list_intend(): for i in xrange(Time): [1 for i in xrange(N)] if __name__ == '__main__': array= [list_append,list_extend,list_extend_list,list_intend] time.time() for function in array: clock = time.time() function() print (time.time() - clock) / Time
çµæ
python2.7 | pypy | |
list_append | 1.137867 | 0.595848 |
list_extend | 2.113609 | 0.663510 |
list_extend_list | 0.396939 | 0.000001 |
list_intend | 0.482634 | 0.0554735898972 |
ããæ¡å¤é«éåããã¦ãããã ç¾ç¶ãscipyã¨ã対å¿ãã¦ãªãã®ããã£ã¦ãããã£ãé¨åãå¾®å¦ãªãã ããªãã»ã»ã»