How to make gmpy array operations faster?

I had speed issues when trying to use the gmpy module.

import numpy as np import gmpy2 as gm N = 1000 a = range(N) %timeit [gm.sin(x) for x in a] # 100 loops, best of 3: 7.39 ms per loop %timeit np.sin(a) # 10000 loops, best of 3: 198 us per loop 

I was wondering if I could somehow speed up this calculation. I thought JIT or multiprocessing might help, but I did not understand how to do this.

Any help would be greatly appreciated. If you want me to post additional information, please let me know.

0
source share
1 answer

I was curious to know how much you can increase productivity, so I wrote a new function for gmpy2 , which calculated the entire list sin in C. Unfortunately, there was no 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 Global Interpreter Lock (GIL), so the thread will not help.

Multiprocessing can help, but you may have to parallelize parts of the code that take seconds (or more) to execute in order to overcome the overhead of transferring data to another process.

A software-based floating point of arbitrary precision is only slower than a native floating point.

+2
source

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


All Articles