How do I make gmpy array operations faster?

后端 未结 1 717
遇见更好的自我
遇见更好的自我 2021-01-26 02:57

I\'ve been having trouble with speed while trying to utilise the gmpy module.

import numpy as np
import gmpy2 as gm
N = 1000
a = range(N)
%timeit [gm.sin(x) for          


        
相关标签:
1条回答
  • 2021-01-26 03:16

    I was curious to see how much performance increase would be possible so wrote a new function for gmpy2 that calculated the sin of a list entirely in C. Unfortunately, there wasn't much improvement.

    %timeit [gmpy2.sin(x) for x in a]
    100 loops, best of 3: 4.85 ms per loop
    %timeit map(gmpy2.sin, a)
    100 loops, best of 3: 4.59 ms per loop
    %timeit gmpy2.vector(a)
    100 loops, best of 3: 4.44 ms per loop
    

    gmpy2 does not release the Global Interpreter Lock (GIL) so threading won't help.

    Multiprocessing may help but you will probably need to parallelize portions of code that take seconds (or longer) to execute to overcome the overhead of passing data to another process.

    Software-based, arbitrary-precision floating point is just slower than native floating point.

    0 讨论(0)
提交回复
热议问题