Best way to do

pauld11718 pauld11718 at gmail.com
Sat Apr 25 12:37:23 CEST 2015


import CoolProp.CoolProp as CPpy
import numpy as np
import time

len = 1000
rho = np.zeros(len)
t = np.zeros(len)
eta = np.zeros(len)
x = np.zeros(len)

def PyDir(p,h,hndl):
    for i in range(1, len):
        rho[i] = hndl.PropsSI("D","P",p[i],"H",h[i],"Water")
        t[i] = hndl.PropsSI('T','P',p[i],'H',h[i],'Water')
        x[i] = hndl.PropsSI('Q','P',p[i],'H',h[i],'Water')
        eta[i] = hndl.PropsSI('V','P',p[i],'H',h[i],'Water')
    return rho,t,eta,x
    
def PyDirn(p,h,hndl):
        rho = hndl.PropsSI("D","P",p,"H",h,"Water")
        t = hndl.PropsSI('T','P',p,'H',h,'Water')
        x = hndl.PropsSI('Q','P',p,'H',h,'Water')
        eta = hndl.PropsSI('V','P',p,'H',h,'Water')
        return rho,t,eta,x

def PyDirVec(p,h,hndl):
    rho = hndl.PropsSI("D","P",p,"H",h,"Water")
    t = hndl.PropsSI('T','P',p,'H',h,'Water')
    x = hndl.PropsSI('Q','P',p,'H',h,'Water')
    eta = hndl.PropsSI('V','P',p,'H',h,'Water')
    return rho,t,eta,x

h = 1e3*np.linspace(700,1500,len)
p = 1e6*np.linspace(2.8,3,len)

t1 = time.time()
(rho,t,eta,x) = PyDir(p,h,CPpy)
t2 = time.time()
print('%e'%((t2 - t1)))

t1 = time.time()
for i in range(1,len):
    (rho[i],t[i],eta[i],x[i]) = PyDirn(p[i],h[i],CPpy)
t2 = time.time()
print('%e'%((t2 - t1)))

t1 = time.time()
(rho,t,eta,x) = PyDirVec(p,h,CPpy)
t2 = time.time()
print('%e'%((t2 - t1)))

5.214521e+00
5.149483e+00
4.670270e+00

What is the best way to do the same for best computational speed?



More information about the Python-list mailing list