I write a python script to do interpolation work. It will be called in Unity for simulation.
The problem is that when I run the program in PyCharm console, it only takes about 2ms.
But when I run this script in CMD like how Unity call python scripts, it takes 200-400ms.
the main code is as follows:
from time import time
start = time()
import numpy as np
from scipy.interpolate import interpn
x = np.linspace(0, 10, 20)
y = np.linspace(0, 10, 20)
z = np.linspace(0, 10, 20)
def value_func(x, y, z):
return 3*x*x * y + y - z + 100
points = (x, y, z)
values = value_func(*np.meshgrid(*points, indexing='ij'))
point_test = np.random.random([100, 3])
t = np.linspace(0, 10, 50)
xt, yt, zt = np.meshgrid(t, t, t)
point = np.array([2.21, 3.12, 1.15])
result = interpn(points, values, point_test, method='linear')
if __name__ == '__main__':
paras_output = result
# print(paras_output)
print('run time:' + str(time()-start))
Python version: 3.9.13
IDE: Pycharm
The simulation program need to call this python script frequently, the current runtime is not acceptable.
What should I do?