Why is Pypy slower to add numpy arrays?

To test the claims that Pypy JIT is significantly faster, I wrote simple code that repeatedly adds two 1200x1200 sized arrays. My code is as follows

import numpy as np
import random

a=np.zeros((1200, 1200), dtype=np.float32)
b=np.zeros((1200, 1200), dtype=np.float32)
import timeit
#Start timer
start=timeit.default_timer()
#Initialize the arrays
for j in range(1200):
    for k in range(1200):
        a[j][k]=random.random()
        b[j][k]=random.random()
#Repeatedly add the arrays    
for j in range(10):
    a=np.add(a,b)
#Stop timer and display the results
stop=timeit.default_timer()
print stop-start

With a regular python, the time spent on execution is about 1.2 - 1.5 seconds. However, with Pypy, is this more than 15 seconds? Also in the above case, I added arrays only 10 times. If I increase this value to 1000, my computer will stop responding. I found that this is due to the fact that almost all RAM was consumed when using pypy. Am I doing something wrong? Or is the problem different?

+4
source share
2 answers

pypy numpy , , , , , , .

numpy.ndarray,

numpy

. pypy , :

import gc
del my_array
gc.collect()

pypy . , gc.collect() , .

, - CFFI : https://docs.scipy.org/doc/numpy/reference/arrays.interface.html

numpy, / .

+1

JIT , python. NumPy C, JIT . , PyPy , PyPy, RPython, NumPy, C, , , NumPy PyPy, C.

CFFI , , C, , .

, . .

0

Source: https://habr.com/ru/post/1671155/


All Articles