Why is numba faster than numpy here?

后端 未结 4 1589
庸人自扰
庸人自扰 2020-12-24 02:26

I can\'t figure out why numba is beating numpy here (over 3x). Did I make some fundamental error in how I am benchmarking here? Seems like the perfect situation for numpy,

4条回答
  •  长情又很酷
    2020-12-24 03:01

    When you ask numpy to do:

    x = x*2 - ( y * 55 )
    

    It is internally translated to something like:

    tmp1 = y * 55
    tmp2 = x * 2
    tmp3 = tmp2 - tmp1
    x = tmp3
    

    Each of those temps are arrays that have to be allocated, operated on, and then deallocated. Numba, on the other hand, handles things one item at a time, and doesn't have to deal with that overhead.

提交回复
热议问题