我开始将我的一些Matlab脚本翻译成Julia,并尝试比较性能。在这里,我遇到了一个看似简单的问题,但没有通过快速搜索找到答案。当我从控制台运行Julia脚本时,即键入“ julia test_FAS2SA.jl”,它将在屏幕上显示“ 3.116226秒”,几乎是相应的matlab脚本运行时间的30倍。
然后,我进入julia环境并键入“ include(“ test_FAS2SA.jl”)“,它显示“ 1.368429秒”。但是,当我只键入“ @time SA,PF = FAS2SA(FAS1,f_FAS,10.0,f_SA,0.05);”时,它会显示“ 0.033920秒”。我想知道函数FAS2SA的实际运行时间是多少,并且会打印不同的时间。
我的平台是Windows 7专业版Julia 1.10。脚本“ test_FAS2SA.jl”和输入文件粘贴如下。
# test JuliaFunc
using DelimitedFiles
# import Pkg; Pkg.add("time")
using QuadGK
function getH_SDF(D,fn,freq)
# PURPOSE
# get transfer function of a SDOF oscilator
# acc response to acc excitation
# INPUT
# D - damping ratio
# fn - fundamental frequency of the SDOF (Hz)
# freq - frequency array (Hz)
# OUTPUT
# absH - Amplitude of the transfer function
N=length(freq)
H=complex(zeros(N))
for i=1:N
f=freq[i]
H[i]=(-fn^2)/((f^2-fn^2)-(2*f*fn*D*1im))
end
return abs.(H)
end
function trapz(x, y)
# Trapezoidal integration rule
local n = length(x)
if (length(y) != n)
error("Vectors 'x', 'y' must be of same length")
end
r = 0.0
if n == 1; return r; end
for i in 2:n
r += (x[i] - x[i-1]) * (y[i] + y[i-1])
end
#= correction -h^2/12 * (f'(b) - f'(a))
ha = x[2] - x[1]
he = x[end] - x[end-1]
ra = (y[2] - y[1]) / ha
re = (y[end] - y[end-1]) / he
r/2 - ha*he/12 * (re - ra)
=#
return r/2
end
function getmoment(Y,f,n)
N=length(Y)
S=zeros(N)
for i=1:N
S[i]=(2.0*pi*f[i])^n*Y[i]^2
end
return 2.0*trapz(f,S)
end
function getXmax(Y,F,T_rms)
moment0=getmoment(Y,F,0)
moment2=getmoment(Y,F,2)
moment4=getmoment(Y,F,4)
Y_rms=(moment0/T_rms)^0.5 # rms value
Ne=1.0/pi*(moment4/moment2)^0.5*T_rms # number of extrema
xi=(moment2^2/moment0/moment4)^0.5 # number of width
#temp=(2*log(xi*Ne))^0.5
#PF(i)=temp+0.5772/temp
Func(x)=1-(1-xi*exp(-x^2))^Ne
#Fun=@(x) 1-(1-xi.*exp(-x.^2)).^Ne
Tmp,e = QuadGK.quadgk(Func,0,Inf)
PF = sqrt(2.0)*Tmp
Ymax=PF*Y_rms
return Ymax
end
function FAS2SA(FAS,F,T_gm,freq, damping)
# INPUT
# FAS - Fourier Amplitude Spectrum
# F - Frquency array corresponding FAS (Hz)
# T_gm - ground motion duration (sec)
# freq - fundametnal frequency of SDOF oscilator (Hz)
# damping - damping ratio of SDOF oscilator
# OUTPUT
# SA - Spectral acceleration (g)
# PF - Peak Factor
n_T=length(freq)
SA=zeros(n_T)
PF=zeros(n_T)
for i=1:n_T
H=getH_SDF(damping,freq[i],F) # get transfer function of SDOF oscilator
Y=FAS.*H # FAS of acc response of oscilator
Tn=1.0/freq[i] # fundamantal period
T0=Tn/2.0/pi/damping #oscilator duration
gamma=T_gm/Tn
n_val=3.0
alpha=1.0 / 3.0
T_rms=T_gm+T0*(gamma^n_val/(gamma^n_val+alpha)) # total duration
moment0=getmoment(Y,F,0)
moment2=getmoment(Y,F,2)
moment4=getmoment(Y,F,4)
Y_rms=(moment0/T_rms)^0.5 # rms value
Ne=1/pi*(moment4/moment2)^0.5*T_gm # number of extrema
# note that here use T_gm not T_rms (Refer to Boore and Joyer, 1984)
xi=(moment2^2/moment0/moment4)^0.5 # number of width
#temp=(2*log(xi*Ne))^0.5
#PF(i)=temp+0.5772/temp
Fun(x)= 1-(1-xi*exp(-x^2))^Ne
Q_tmp,e_tmp = QuadGK.quadgk(Fun,0,Inf)
PF1 = 2^0.5*Q_tmp
Ymax=PF1*Y_rms
SA[i]=Ymax
PF[i]=PF1
end
return (SA,PF)
end
T=readdlm("period.dat")
f_SA=1.0 ./ T
#println(vs)
FAS=readdlm("FAS.dat")
f_FAS=FAS[:,1]
FAS1=FAS[:,2]
println(@time SA,PF=FAS2SA(FAS1,f_FAS,10.0,f_SA, 0.05))
文件“ period.dat”
0.01
0.01103674
0.012180962
0.01344381
0.014837583
0.016375854
0.018073604
0.019947366
0.022015388
0.024297811
0.026816861
0.029597071
0.032665516
0.036052079
0.039789741
0.043914901
0.048467732
0.053492574
0.05903836
0.065159101
0.071914402
0.079370053
0.08759866
0.096680359
0.106703594
0.117765978
0.129975243
0.14345029
0.158322349
0.174736253
0.192851851
0.212845565
0.234912106
0.259266373
0.286145543
0.315811383
0.348552798
0.384688645
0.424570838
0.468587776
0.517168124
0.570784988
0.629960525
0.695271024
0.76735252
0.84690699
0.934709187
1.031614184
1.138565706
1.256605315
1.386882557
1.530666156
1.689356369
1.864498624
2.057798569
2.271138684
2.506596612
2.766465394
3.053275801
3.369820977
3.719183643
4.104766118
4.530323453
5
文件“ FAS.dat”
5.00E-02 7.29E-03
5.03E-02 7.38E-03
5.07E-02 7.46E-03
5.10E-02 7.55E-03
5.14E-02 7.63E-03
5.17E-02 7.72E-03
5.21E-02 7.81E-03
5.24E-02 7.90E-03
5.28E-02 7.99E-03
5.31E-02 8.08E-03
5.35E-02 8.17E-03
5.39E-02 8.27E-03
5.42E-02 8.36E-03
5.46E-02 8.46E-03
5.50E-02 8.55E-03
5.53E-02 8.65E-03
5.57E-02 8.75E-03
5.61E-02 8.84E-03
5.65E-02 8.94E-03
5.68E-02 9.04E-03
5.72E-02 9.14E-03
5.76E-02 9.24E-03
5.80E-02 9.35E-03
5.84E-02 9.45E-03
5.88E-02 9.55E-03
5.92E-02 9.66E-03
5.96E-02 9.76E-03
6.00E-02 9.87E-03
6.04E-02 9.98E-03
6.08E-02 1.01E-02
6.12E-02 1.02E-02
6.16E-02 1.03E-02
6.21E-02 1.04E-02
6.25E-02 1.05E-02
6.29E-02 1.06E-02
6.33E-02 1.08E-02
6.38E-02 1.09E-02
6.42E-02 1.10E-02
6.46E-02 1.11E-02
6.51E-02 1.12E-02
6.55E-02 1.13E-02
6.59E-02 1.15E-02
6.64E-02 1.16E-02
6.68E-02 1.17E-02
6.73E-02 1.18E-02
6.78E-02 1.19E-02
6.82E-02 1.21E-02
6.87E-02 1.22E-02
6.91E-02 1.23E-02
6.96E-02 1.24E-02
7.01E-02 1.26E-02
7.06E-02 1.27E-02
7.10E-02 1.28E-02
7.15E-02 1.30E-02
7.20E-02 1.31E-02
7.25E-02 1.32E-02
7.30E-02 1.33E-02
7.35E-02 1.35E-02
7.40E-02 1.36E-02
7.45E-02 1.37E-02
7.50E-02 1.39E-02
7.55E-02 1.40E-02
7.60E-02 1.42E-02
7.65E-02 1.43E-02
7.70E-02 1.44E-02
7.76E-02 1.46E-02
7.81E-02 1.47E-02
7.86E-02 1.49E-02
7.91E-02 1.50E-02
7.97E-02 1.51E-02
8.02E-02 1.53E-02
8.08E-02 1.54E-02
8.13E-02 1.56E-02
8.19E-02 1.57E-02
8.24E-02 1.59E-02
8.30E-02 1.60E-02
8.35E-02 1.62E-02
8.41E-02 1.63E-02
8.47E-02 1.65E-02
8.52E-02 1.66E-02
8.58E-02 1.68E-02
8.64E-02 1.69E-02
8.70E-02 1.71E-02
8.76E-02 1.72E-02
8.82E-02 1.74E-02
8.88E-02 1.75E-02
8.94E-02 1.77E-02
9.00E-02 1.78E-02
9.06E-02 1.80E-02
9.12E-02 1.81E-02
9.18E-02 1.83E-02
9.24E-02 1.85E-02
9.31E-02 1.86E-02
9.37E-02 1.88E-02
9.43E-02 1.89E-02
9.50E-02 1.91E-02
9.56E-02 1.92E-02
9.63E-02 1.94E-02
9.69E-02 1.96E-02
9.76E-02 1.97E-02
9.82E-02 1.99E-02
9.89E-02 2.01E-02
9.96E-02 2.02E-02
1.00E-01 2.04E-02
1.01E-01 2.05E-02
1.02E-01 2.07E-02
1.02E-01 2.09E-02
1.03E-01 2.10E-02
1.04E-01 2.12E-02
1.04E-01 2.14E-02
1.05E-01 2.15E-02
1.06E-01 2.17E-02
1.07E-01 2.19E-02
1.07E-01 2.20E-02
1.08E-01 2.22E-02
1.09E-01 2.24E-02
1.09E-01 2.25E-02
1.10E-01 2.27E-02
1.11E-01 2.29E-02
1.12E-01 2.30E-02
1.12E-01 2.32E-02
1.13E-01 2.34E-02
1.14E-01 2.36E-02
1.15E-01 2.37E-02
1.16E-01 2.39E-02
1.16E-01 2.41E-02
1.17E-01 2.42E-02
1.18E-01 2.44E-02
1.19E-01 2.46E-02
1.19E-01 2.48E-02
1.20E-01 2.49E-02
1.21E-01 2.51E-02
1.22E-01 2.53E-02
1.23E-01 2.54E-02
1.24E-01 2.56E-02
1.24E-01 2.58E-02
1.25E-01 2.60E-02
1.26E-01 2.61E-02
1.27E-01 2.63E-02
1.28E-01 2.65E-02
1.29E-01 2.66E-02
1.30E-01 2.68E-02
1.30E-01 2.70E-02
1.31E-01 2.72E-02
1.32E-01 2.73E-02
1.33E-01 2.75E-02
1.34E-01 2.77E-02
1.35E-01 2.79E-02
1.36E-01 2.80E-02
1.37E-01 2.82E-02
1.38E-01 2.84E-02
1.39E-01 2.85E-02
1.40E-01 2.87E-02
1.40E-01 2.89E-02
1.41E-01 2.91E-02
1.42E-01 2.92E-02
1.43E-01 2.94E-02
1.44E-01 2.96E-02
1.45E-01 2.97E-02
1.46E-01 2.99E-02
1.47E-01 3.01E-02
1.48E-01 3.03E-02
1.49E-01 3.04E-02
1.50E-01 3.06E-02
1.51E-01 3.08E-02
1.52E-01 3.09E-02
1.53E-01 3.11E-02
1.54E-01 3.13E-02
1.55E-01 3.14E-02
1.57E-01 3.16E-02
1.58E-01 3.18E-02
1.59E-01 3.20E-02
1.60E-01 3.21E-02
1.61E-01 3.23E-02
1.62E-01 3.24E-02
1.63E-01 3.26E-02
1.64E-01 3.27E-02
1.65E-01 3.29E-02
1.66E-01 3.30E-02
1.67E-01 3.32E-02
1.69E-01 3.34E-02
1.70E-01 3.35E-02
1.71E-01 3.37E-02
1.72E-01 3.38E-02
1.73E-01 3.39E-02
1.74E-01 3.41E-02
1.76E-01 3.42E-02
1.77E-01 3.44E-02
1.78E-01 3.45E-02
1.79E-01 3.47E-02
1.80E-01 3.48E-02
1.82E-01 3.50E-02
1.83E-01 3.51E-02
1.84E-01 3.53E-02
1.85E-01 3.54E-02
1.87E-01 3.56E-02
1.88E-01 3.57E-02
1.89E-01 3.58E-02
1.90E-01 3.60E-02
1.92E-01 3.61E-02
1.93E-01 3.63E-02
1.94E-01 3.64E-02
1.96E-01 3.65E-02
1.97E-01 3.67E-02
1.98E-01 3.68E-02
2.00E-01 3.69E-02
2.01E-01 3.71E-02
2.02E-01 3.72E-02
2.04E-01 3.73E-02
2.05E-01 3.75E-02
2.06E-01 3.76E-02
2.08E-01 3.77E-02
2.09E-01 3.79E-02
2.11E-01 3.80E-02
2.12E-01 3.81E-02
2.14E-01 3.83E-02
2.15E-01 3.84E-02
2.16E-01 3.85E-02
2.18E-01 3.87E-02
2.19E-01 3.88E-02
2.21E-01 3.89E-02
2.22E-01 3.90E-02
2.24E-01 3.92E-02
2.25E-01 3.93E-02
2.27E-01 3.94E-02
2.28E-01 3.95E-02
2.30E-01 3.97E-02
2.32E-01 3.98E-02
2.33E-01 3.99E-02
2.35E-01 4.00E-02
2.36E-01 4.01E-02
2.38E-01 4.03E-02
2.40E-01 4.04E-02
2.41E-01 4.05E-02
2.43E-01 4.06E-02
2.44E-01 4.07E-02
2.46E-01 4.09E-02
2.48E-01 4.10E-02
2.49E-01 4.11E-02
2.51E-01 4.12E-02
2.53E-01 4.13E-02
2.55E-01 4.14E-02
2.56E-01 4.16E-02
2.58E-01 4.17E-02
2.60E-01 4.18E-02
2.61E-01 4.19E-02
2.63E-01 4.20E-02
2.65E-01 4.21E-02
2.67E-01 4.22E-02
2.69E-01 4.23E-02
2.70E-01 4.24E-02
2.72E-01 4.25E-02
2.74E-01 4.27E-02
2.76E-01 4.28E-02
2.78E-01 4.29E-02
2.80E-01 4.30E-02
2.82E-01 4.31E-02
2.84E-01 4.32E-02
2.85E-01 4.33E-02
2.87E-01 4.34E-02
2.89E-01 4.35E-02
2.91E-01 4.36E-02
2.93E-01 4.37E-02
2.95E-01 4.38E-02
2.97E-01 4.39E-02
2.99E-01 4.40E-02
3.01E-01 4.41E-02
3.03E-01 4.42E-02
3.05E-01 4.43E-02
3.07E-01 4.44E-02
3.10E-01 4.45E-02
3.12E-01 4.46E-02
3.14E-01 4.47E-02
3.16E-01 4.48E-02
3.18E-01 4.49E-02
3.20E-01 4.50E-02
3.22E-01 4.51E-02
3.25E-01 4.52E-02
3.27E-01 4.53E-02
3.29E-01 4.54E-02
3.31E-01 4.55E-02
3.33E-01 4.56E-02
3.36E-01 4.57E-02
3.38E-01 4.58E-02
3.40E-01 4.59E-02
3.43E-01 4.59E-02
3.45E-01 4.60E-02
3.47E-01 4.61E-02
3.50E-01 4.62E-02
3.52E-01 4.63E-02
3.54E-01 4.64E-02
3.57E-01 4.65E-02
3.59E-01 4.66E-02
3.62E-01 4.67E-02
3.64E-01 4.68E-02
3.66E-01 4.69E-02
3.69E-01 4.69E-02
3.71E-01 4.70E-02
3.74E-01 4.71E-02
3.77E-01 4.72E-02
3.79E-01 4.73E-02
3.82E-01 4.74E-02
3.84E-01 4.75E-02
3.87E-01 4.76E-02
3.89E-01 4.76E-02
3.92E-01 4.77E-02
3.95E-01 4.78E-02
3.97E-01 4.79E-02
4.00E-01 4.80E-02
4.03E-01 4.81E-02
4.06E-01 4.82E-02
4.08E-01 4.82E-02
4.11E-01 4.83E-02
4.14E-01 4.84E-02
4.17E-01 4.85E-02
4.19E-01 4.86E-02
4.22E-01 4.87E-02
4.25E-01 4.88E-02
4.28E-01 4.88E-02
4.31E-01 4.89E-02
4.34E-01 4.90E-02
4.37E-01 4.91E-02
4.40E-01 4.92E-02
4.43E-01 4.93E-02
4.46E-01 4.93E-02
4.49E-01 4.94E-02
4.52E-01 4.95E-02
4.55E-01 4.96E-02
4.58E-01 4.97E-02
4.61E-01 4.97E-02
4.64E-01 4.98E-02
4.67E-01 4.99E-02
4.71E-01 5.00E-02
4.74E-01 5.01E-02
4.77E-01 5.02E-02
4.80E-01 5.02E-02
4.83E-01 5.03E-02
4.87E-01 5.04E-02
4.90E-01 5.05E-02
4.93E-01 5.06E-02
4.97E-01 5.06E-02
5.00E-01 5.07E-02
5.03E-01 5.08E-02
5.07E-01 5.09E-02
5.10E-01 5.10E-02
5.14E-01 5.10E-02
5.17E-01 5.11E-02
5.21E-01 5.11E-02
5.24E-01 5.12E-02
5.28E-01 5.12E-02
5.31E-01 5.13E-02
5.35E-01 5.13E-02
5.39E-01 5.14E-02
5.42E-01 5.15E-02
5.46E-01 5.15E-02
5.50E-01 5.16E-02
5.53E-01 5.16E-02
5.57E-01 5.17E-02
5.61E-01 5.17E-02
5.65E-01 5.18E-02
5.68E-01 5.18E-02
5.72E-01 5.19E-02
5.76E-01 5.19E-02
5.80E-01 5.20E-02
5.84E-01 5.20E-02
5.88E-01 5.21E-02
5.92E-01 5.21E-02
5.96E-01 5.22E-02
6.00E-01 5.22E-02
6.04E-01 5.23E-02
6.08E-01 5.24E-02
6.12E-01 5.24E-02
6.16E-01 5.25E-02
6.21E-01 5.25E-02
6.25E-01 5.26E-02
6.29E-01 5.26E-02
6.33E-01 5.27E-02
6.38E-01 5.27E-02
6.42E-01 5.28E-02
6.46E-01 5.28E-02
6.51E-01 5.29E-02
6.55E-01 5.29E-02
6.59E-01 5.30E-02
6.64E-01 5.30E-02
6.68E-01 5.31E-02
6.73E-01 5.31E-02
6.78E-01 5.32E-02
6.82E-01 5.32E-02
6.87E-01 5.33E-02
6.91E-01 5.33E-02
6.96E-01 5.34E-02
7.01E-01 5.34E-02
7.06E-01 5.35E-02
7.10E-01 5.35E-02
7.15E-01 5.36E-02
7.20E-01 5.36E-02
7.25E-01 5.37E-02
7.30E-01 5.37E-02
7.35E-01 5.38E-02
7.40E-01 5.38E-02
7.45E-01 5.39E-02
7.50E-01 5.39E-02
7.55E-01 5.40E-02
7.60E-01 5.40E-02
7.65E-01 5.41E-02
7.70E-01 5.41E-02
7.76E-01 5.42E-02
7.81E-01 5.42E-02
7.86E-01 5.43E-02
7.91E-01 5.43E-02
7.97E-01 5.44E-02
8.02E-01 5.44E-02
8.08E-01 5.45E-02
8.13E-01 5.45E-02
8.19E-01 5.46E-02
8.24E-01 5.46E-02
8.30E-01 5.47E-02
8.35E-01 5.47E-02
8.41E-01 5.47E-02
8.47E-01 5.48E-02
8.52E-01 5.48E-02
8.58E-01 5.48E-02
8.64E-01 5.49E-02
8.70E-01 5.49E-02
8.76E-01 5.49E-02
8.82E-01 5.50E-02
8.88E-01 5.50E-02
8.94E-01 5.50E-02
9.00E-01 5.51E-02
9.06E-01 5.51E-02
9.12E-01 5.51E-02
9.18E-01 5.51E-02
9.24E-01 5.52E-02
9.31E-01 5.52E-02
9.37E-01 5.52E-02
9.43E-01 5.53E-02
9.50E-01 5.53E-02
9.56E-01 5.53E-02
9.63E-01 5.53E-02
9.69E-01 5.54E-02
9.76E-01 5.54E-02
9.82E-01 5.54E-02
9.89E-01 5.55E-02
9.96E-01 5.55E-02
1.00E+00 5.55E-02
1.01E+00 5.56E-02
1.02E+00 5.56E-02
1.02E+00 5.56E-02
1.03E+00 5.56E-02
1.04E+00 5.57E-02
1.04E+00 5.57E-02
1.05E+00 5.57E-02
1.06E+00 5.58E-02
1.07E+00 5.58E-02
1.07E+00 5.58E-02
1.08E+00 5.58E-02
1.09E+00 5.59E-02
1.09E+00 5.59E-02
1.10E+00 5.59E-02
1.11E+00 5.60E-02
1.12E+00 5.60E-02
1.12E+00 5.60E-02
1.13E+00 5.60E-02
1.14E+00 5.61E-02
1.15E+00 5.61E-02
1.16E+00 5.61E-02
1.16E+00 5.62E-02
1.17E+00 5.62E-02
1.18E+00 5.62E-02
1.19E+00 5.62E-02
1.19E+00 5.63E-02
1.20E+00 5.63E-02
1.21E+00 5.63E-02
1.22E+00 5.64E-02
1.23E+00 5.64E-02
1.24E+00 5.64E-02
1.24E+00 5.64E-02
1.25E+00 5.65E-02
1.26E+00 5.65E-02
1.27E+00 5.65E-02
1.28E+00 5.65E-02
1.29E+00 5.65E-02
1.30E+00 5.65E-02
1.30E+00 5.65E-02
1.31E+00 5.65E-02
1.32E+00 5.65E-02
1.33E+00 5.65E-02
1.34E+00 5.65E-02
1.35E+00 5.65E-02
1.36E+00 5.65E-02
1.37E+00 5.65E-02
1.38E+00 5.65E-02
1.39E+00 5.66E-02
1.40E+00 5.66E-02
1.40E+00 5.66E-02
1.41E+00 5.66E-02
1.42E+00 5.66E-02
1.43E+00 5.66E-02
1.44E+00 5.66E-02
1.45E+00 5.66E-02
1.46E+00 5.66E-02
1.47E+00 5.66E-02
1.48E+00 5.66E-02
1.49E+00 5.66E-02
1.50E+00 5.66E-02
1.51E+00 5.66E-02
1.52E+00 5.66E-02
1.53E+00 5.66E-02
1.54E+00 5.66E-02
1.55E+00 5.66E-02
1.57E+00 5.66E-02
1.58E+00 5.66E-02
1.59E+00 5.66E-02
1.60E+00 5.66E-02
1.61E+00 5.66E-02
1.62E+00 5.66E-02
1.63E+00 5.66E-02
1.64E+00 5.66E-02
1.65E+00 5.66E-02
1.66E+00 5.66E-02
1.67E+00 5.67E-02
1.69E+00 5.67E-02
1.70E+00 5.67E-02
1.71E+00 5.67E-02
1.72E+00 5.67E-02
1.73E+00 5.67E-02
1.74E+00 5.67E-02
1.76E+00 5.67E-02
1.77E+00 5.67E-02
1.78E+00 5.67E-02
1.79E+00 5.67E-02
1.80E+00 5.67E-02
1.82E+00 5.67E-02
1.83E+00 5.67E-02
1.84E+00 5.66E-02
1.85E+00 5.66E-02
1.87E+00 5.66E-02
1.88E+00 5.66E-02
1.89E+00 5.66E-02
1.90E+00 5.66E-02
1.92E+00 5.66E-02
1.93E+00 5.66E-02
1.94E+00 5.66E-02
1.96E+00 5.66E-02
1.97E+00 5.66E-02
1.98E+00 5.66E-02
2.00E+00 5.66E-02
2.01E+00 5.66E-02
2.02E+00 5.66E-02
2.04E+00 5.66E-02
2.05E+00 5.66E-02
2.06E+00 5.66E-02
2.08E+00 5.66E-02
2.09E+00 5.66E-02
2.11E+00 5.66E-02
2.12E+00 5.66E-02
2.14E+00 5.66E-02
2.15E+00 5.66E-02
2.16E+00 5.65E-02
2.18E+00 5.65E-02
2.19E+00 5.65E-02
2.21E+00 5.65E-02
2.22E+00 5.65E-02
2.24E+00 5.65E-02
2.25E+00 5.65E-02
2.27E+00 5.65E-02
2.28E+00 5.64E-02
2.30E+00 5.64E-02
2.32E+00 5.63E-02
2.33E+00 5.62E-02
2.35E+00 5.62E-02
2.36E+00 5.61E-02
2.38E+00 5.61E-02
2.40E+00 5.60E-02
2.41E+00 5.60E-02
2.43E+00 5.59E-02
2.44E+00 5.58E-02
2.46E+00 5.58E-02
2.48E+00 5.57E-02
2.49E+00 5.57E-02
2.51E+00 5.56E-02
2.53E+00 5.55E-02
2.55E+00 5.55E-02
2.56E+00 5.54E-02
2.58E+00 5.54E-02
2.60E+00 5.53E-02
2.61E+00 5.52E-02
2.63E+00 5.52E-02
2.65E+00 5.51E-02
2.67E+00 5.50E-02
2.69E+00 5.50E-02
2.70E+00 5.49E-02
2.72E+00 5.48E-02
2.74E+00 5.48E-02
2.76E+00 5.47E-02
2.78E+00 5.46E-02
2.80E+00 5.46E-02
2.82E+00 5.45E-02
2.84E+00 5.44E-02
2.85E+00 5.44E-02
2.87E+00 5.43E-02
2.89E+00 5.42E-02
2.91E+00 5.42E-02
2.93E+00 5.41E-02
2.95E+00 5.40E-02
2.97E+00 5.39E-02
2.99E+00 5.39E-02
3.01E+00 5.38E-02
3.03E+00 5.37E-02
3.05E+00 5.37E-02
3.07E+00 5.36E-02
3.10E+00 5.35E-02
3.12E+00 5.34E-02
3.14E+00 5.34E-02
3.16E+00 5.33E-02
3.18E+00 5.32E-02
3.20E+00 5.31E-02
3.22E+00 5.29E-02
3.25E+00 5.28E-02
3.27E+00 5.27E-02
3.29E+00 5.26E-02
3.31E+00 5.24E-02
3.33E+00 5.23E-02
3.36E+00 5.22E-02
3.38E+00 5.20E-02
3.40E+00 5.19E-02
3.43E+00 5.18E-02
3.45E+00 5.16E-02
3.47E+00 5.15E-02
3.50E+00 5.14E-02
3.52E+00 5.13E-02
3.54E+00 5.11E-02
3.57E+00 5.10E-02
3.59E+00 5.09E-02
3.62E+00 5.07E-02
3.64E+00 5.06E-02
3.66E+00 5.05E-02
3.69E+00 5.03E-02
3.71E+00 5.02E-02
3.74E+00 5.00E-02
3.77E+00 4.99E-02
3.79E+00 4.98E-02
3.82E+00 4.96E-02
3.84E+00 4.95E-02
3.87E+00 4.94E-02
3.89E+00 4.92E-02
3.92E+00 4.91E-02
3.95E+00 4.89E-02
3.97E+00 4.88E-02
4.00E+00 4.86E-02
4.03E+00 4.85E-02
4.06E+00 4.84E-02
4.08E+00 4.82E-02
4.11E+00 4.81E-02
4.14E+00 4.79E-02
4.17E+00 4.78E-02
4.19E+00 4.76E-02
4.22E+00 4.75E-02
4.25E+00 4.73E-02
4.28E+00 4.72E-02
4.31E+00 4.71E-02
4.34E+00 4.69E-02
4.37E+00 4.68E-02
4.40E+00 4.66E-02
4.43E+00 4.65E-02
4.46E+00 4.63E-02
4.49E+00 4.62E-02
4.52E+00 4.60E-02
4.55E+00 4.59E-02
4.58E+00 4.57E-02
4.61E+00 4.56E-02
4.64E+00 4.54E-02
4.67E+00 4.52E-02
4.71E+00 4.51E-02
4.74E+00 4.49E-02
4.77E+00 4.48E-02
4.80E+00 4.46E-02
4.83E+00 4.45E-02
4.87E+00 4.43E-02
4.90E+00 4.42E-02
4.93E+00 4.40E-02
4.97E+00 4.38E-02
5.00E+00 4.37E-02
5.03E+00 4.35E-02
5.07E+00 4.34E-02
5.10E+00 4.32E-02
5.14E+00 4.30E-02
5.17E+00 4.29E-02
5.21E+00 4.27E-02
5.24E+00 4.26E-02
5.28E+00 4.24E-02
5.31E+00 4.22E-02
5.35E+00 4.21E-02
5.39E+00 4.19E-02
5.42E+00 4.17E-02
5.46E+00 4.16E-02
5.50E+00 4.14E-02
5.53E+00 4.13E-02
5.57E+00 4.11E-02
5.61E+00 4.09E-02
5.65E+00 4.08E-02
5.68E+00 4.06E-02
5.72E+00 4.04E-02
5.76E+00 4.03E-02
5.80E+00 4.01E-02
5.84E+00 3.99E-02
5.88E+00 3.97E-02
5.92E+00 3.96E-02
5.96E+00 3.94E-02
6.00E+00 3.92E-02
6.04E+00 3.91E-02
6.08E+00 3.89E-02
6.12E+00 3.87E-02
6.16E+00 3.84E-02
6.21E+00 3.82E-02
6.25E+00 3.80E-02
6.29E+00 3.78E-02
6.33E+00 3.76E-02
6.38E+00 3.74E-02
6.42E+00 3.72E-02
6.46E+00 3.70E-02
6.51E+00 3.68E-02
6.55E+00 3.65E-02
6.59E+00 3.63E-02
6.64E+00 3.61E-02
6.68E+00 3.59E-02
6.73E+00 3.57E-02
6.78E+00 3.55E-02
6.82E+00 3.53E-02
6.87E+00 3.51E-02
6.91E+00 3.48E-02
6.96E+00 3.46E-02
7.01E+00 3.44E-02
7.06E+00 3.42E-02
7.10E+00 3.40E-02
7.15E+00 3.38E-02
7.20E+00 3.36E-02
7.25E+00 3.34E-02
7.30E+00 3.31E-02
7.35E+00 3.29E-02
7.40E+00 3.27E-02
7.45E+00 3.25E-02
7.50E+00 3.23E-02
7.55E+00 3.21E-02
7.60E+00 3.19E-02
7.65E+00 3.17E-02
7.70E+00 3.15E-02
7.76E+00 3.12E-02
7.81E+00 3.10E-02
7.86E+00 3.08E-02
7.91E+00 3.06E-02
7.97E+00 3.04E-02
8.02E+00 3.02E-02
8.08E+00 3.00E-02
8.13E+00 2.98E-02
8.19E+00 2.95E-02
8.24E+00 2.93E-02
8.30E+00 2.91E-02
8.35E+00 2.89E-02
8.41E+00 2.87E-02
8.47E+00 2.85E-02
8.52E+00 2.83E-02
8.58E+00 2.81E-02
8.64E+00 2.79E-02
8.70E+00 2.77E-02
8.76E+00 2.74E-02
8.82E+00 2.72E-02
8.88E+00 2.70E-02
8.94E+00 2.68E-02
9.00E+00 2.66E-02
9.06E+00 2.64E-02
9.12E+00 2.62E-02
9.18E+00 2.60E-02
9.24E+00 2.58E-02
9.31E+00 2.56E-02
9.37E+00 2.54E-02
9.43E+00 2.52E-02
9.50E+00 2.50E-02
9.56E+00 2.48E-02
9.63E+00 2.46E-02
9.69E+00 2.43E-02
9.76E+00 2.41E-02
9.82E+00 2.39E-02
9.89E+00 2.37E-02
9.96E+00 2.35E-02
1.00E+01 2.33E-02
1.01E+01 2.31E-02
1.02E+01 2.29E-02
1.02E+01 2.27E-02
1.03E+01 2.25E-02
1.04E+01 2.23E-02
1.04E+01 2.21E-02
1.05E+01 2.19E-02
1.06E+01 2.17E-02
1.07E+01 2.15E-02
1.07E+01 2.13E-02
1.08E+01 2.11E-02
1.09E+01 2.09E-02
1.09E+01 2.07E-02
1.10E+01 2.06E-02
1.11E+01 2.04E-02
1.12E+01 2.02E-02
1.12E+01 2.00E-02
1.13E+01 1.98E-02
1.14E+01 1.96E-02
1.15E+01 1.94E-02
1.16E+01 1.92E-02
1.16E+01 1.90E-02
1.17E+01 1.88E-02
1.18E+01 1.86E-02
1.19E+01 1.84E-02
1.19E+01 1.83E-02
1.20E+01 1.81E-02
1.21E+01 1.79E-02
1.22E+01 1.77E-02
1.23E+01 1.75E-02
1.24E+01 1.73E-02
1.24E+01 1.72E-02
1.25E+01 1.70E-02
1.26E+01 1.68E-02
1.27E+01 1.66E-02
1.28E+01 1.64E-02
1.29E+01 1.62E-02
1.30E+01 1.61E-02
1.30E+01 1.59E-02
1.31E+01 1.57E-02
1.32E+01 1.55E-02
1.33E+01 1.54E-02
1.34E+01 1.52E-02
1.35E+01 1.50E-02
1.36E+01 1.48E-02
1.37E+01 1.47E-02
1.38E+01 1.45E-02
1.39E+01 1.43E-02
1.40E+01 1.42E-02
1.40E+01 1.40E-02
1.41E+01 1.38E-02
1.42E+01 1.37E-02
1.43E+01 1.35E-02
1.44E+01 1.33E-02
1.45E+01 1.32E-02
1.46E+01 1.30E-02
1.47E+01 1.28E-02
1.48E+01 1.27E-02
1.49E+01 1.25E-02
1.50E+01 1.24E-02
1.51E+01 1.22E-02
1.52E+01 1.21E-02
1.53E+01 1.19E-02
1.54E+01 1.17E-02
1.55E+01 1.16E-02
1.57E+01 1.14E-02
1.58E+01 1.13E-02
1.59E+01 1.11E-02
1.60E+01 1.10E-02
1.61E+01 1.08E-02
1.62E+01 1.07E-02
1.63E+01 1.05E-02
1.64E+01 1.04E-02
1.65E+01 1.03E-02
1.66E+01 1.01E-02
1.67E+01 9.95E-03
1.69E+01 9.80E-03
1.70E+01 9.65E-03
1.71E+01 9.50E-03
1.72E+01 9.35E-03
1.73E+01 9.20E-03
1.74E+01 9.06E-03
1.76E+01 8.91E-03
1.77E+01 8.77E-03
1.78E+01 8.63E-03
1.79E+01 8.49E-03
1.80E+01 8.35E-03
1.82E+01 8.21E-03
1.83E+01 8.08E-03
1.84E+01 7.94E-03
1.85E+01 7.81E-03
1.87E+01 7.68E-03
1.88E+01 7.55E-03
1.89E+01 7.42E-03
1.90E+01 7.29E-03
1.92E+01 7.17E-03
1.93E+01 7.04E-03
1.94E+01 6.92E-03
1.96E+01 6.80E-03
1.97E+01 6.68E-03
1.98E+01 6.56E-03
2.00E+01 6.44E-03
2.01E+01 6.32E-03
2.02E+01 6.21E-03
2.04E+01 6.09E-03
2.05E+01 5.98E-03
2.06E+01 5.87E-03
2.08E+01 5.76E-03
2.09E+01 5.65E-03
2.11E+01 5.55E-03
2.12E+01 5.44E-03
2.14E+01 5.34E-03
2.15E+01 5.23E-03
2.16E+01 5.13E-03
2.18E+01 5.03E-03
2.19E+01 4.93E-03
2.21E+01 4.84E-03
2.22E+01 4.74E-03
2.24E+01 4.64E-03
2.25E+01 4.55E-03
2.27E+01 4.46E-03
2.28E+01 4.37E-03
2.30E+01 4.28E-03
2.32E+01 4.19E-03
2.33E+01 4.10E-03
2.35E+01 4.02E-03
2.36E+01 3.93E-03
2.38E+01 3.85E-03
2.40E+01 3.77E-03
2.41E+01 3.69E-03
2.43E+01 3.61E-03
2.44E+01 3.53E-03
2.46E+01 3.45E-03
2.48E+01 3.37E-03
2.49E+01 3.30E-03
2.51E+01 3.23E-03
2.53E+01 3.15E-03
2.55E+01 3.08E-03
2.56E+01 3.01E-03
2.58E+01 2.94E-03
2.60E+01 2.87E-03
2.61E+01 2.81E-03
2.63E+01 2.74E-03
2.65E+01 2.68E-03
2.67E+01 2.61E-03
2.69E+01 2.55E-03
2.70E+01 2.49E-03
2.72E+01 2.43E-03
2.74E+01 2.37E-03
2.76E+01 2.31E-03
2.78E+01 2.26E-03
2.80E+01 2.20E-03
2.82E+01 2.15E-03
2.84E+01 2.09E-03
2.85E+01 2.04E-03
2.87E+01 1.99E-03
2.89E+01 1.94E-03
2.91E+01 1.89E-03
2.93E+01 1.84E-03
2.95E+01 1.79E-03
2.97E+01 1.74E-03
2.99E+01 1.70E-03
3.01E+01 1.65E-03
3.03E+01 1.61E-03
3.05E+01 1.57E-03
3.07E+01 1.52E-03
3.10E+01 1.48E-03
3.12E+01 1.44E-03
3.14E+01 1.40E-03
3.16E+01 1.36E-03
3.18E+01 1.32E-03
3.20E+01 1.29E-03
3.22E+01 1.25E-03
3.25E+01 1.21E-03
3.27E+01 1.18E-03
3.29E+01 1.15E-03
3.31E+01 1.11E-03
3.33E+01 1.08E-03
3.36E+01 1.05E-03
3.38E+01 1.02E-03
3.40E+01 9.87E-04
3.43E+01 9.57E-04
3.45E+01 9.29E-04
3.47E+01 9.00E-04
3.50E+01 8.73E-04
3.52E+01 8.46E-04
3.54E+01 8.20E-04
3.57E+01 7.94E-04
3.59E+01 7.69E-04
3.62E+01 7.45E-04
3.64E+01 7.21E-04
3.66E+01 6.98E-04
3.69E+01 6.76E-04
3.71E+01 6.54E-04
3.74E+01 6.32E-04
3.77E+01 6.12E-04
3.79E+01 5.92E-04
3.82E+01 5.72E-04
3.84E+01 5.53E-04
3.87E+01 5.34E-04
3.89E+01 5.16E-04
3.92E+01 4.98E-04
3.95E+01 4.81E-04
3.97E+01 4.65E-04
4.00E+01 4.48E-04
4.03E+01 4.33E-04
4.06E+01 4.18E-04
4.08E+01 4.03E-04
4.11E+01 3.88E-04
4.14E+01 3.74E-04
4.17E+01 3.61E-04
4.19E+01 3.48E-04
4.22E+01 3.35E-04
4.25E+01 3.23E-04
4.28E+01 3.11E-04
4.31E+01 2.99E-04
4.34E+01 2.88E-04
4.37E+01 2.77E-04
4.40E+01 2.66E-04
4.43E+01 2.56E-04
4.46E+01 2.46E-04
4.49E+01 2.37E-04
4.52E+01 2.28E-04
4.55E+01 2.19E-04
4.58E+01 2.10E-04
4.61E+01 2.02E-04
4.64E+01 1.94E-04
4.67E+01 1.86E-04
4.71E+01 1.78E-04
4.74E+01 1.71E-04
4.77E+01 1.64E-04
4.80E+01 1.57E-04
4.83E+01 1.51E-04
4.87E+01 1.44E-04
4.90E+01 1.38E-04
4.93E+01 1.32E-04
4.97E+01 1.27E-04
5.00E+01 1.21E-04
答案 0 :(得分:2)
第一次运行Julia时,它将编译所有内容,这需要一点时间。第二次调用任何东西时,它已经被编译并快速运行。
调用两次函数,第二次调用会更快。
运行它时,我的第一个电话是2.750975 seconds
,第二个电话是0.013358 seconds
两次通话我的意思是:
@time SA,PF=FAS2SA(FAS1,f_FAS,10.0,f_SA, 0.05) <---2.750975 seconds
@time SA,PF=FAS2SA(FAS1,f_FAS,10.0,f_SA, 0.05) <---0.013358 seconds
对于计时,使用BenchmarkTools更好,它会多次调用。替换
println(@time SA,PF=FAS2SA(FAS1,f_FAS,10.0,f_SA, 0.05))
与
using BenchmarkTools
@btime FAS2SA($FAS1,$f_FAS,10.0,$f_SA, 0.05)
输出为10.669 ms (125187 allocations: 6.17 MiB)
请注意您正在使用多少个分配和内存。这意味着您的代码可能仍会更快。我不会对其进行优化,因为它太长了。但我保证,如果您摆脱了所有这些分配,可以大大提高代码的速度。
通过实践,您将能够编写出与C和Fortran一样快的代码(我在非平凡的代码上已经见过好几次了),但这确实需要实践。您需要避免建立临时数组。
我建议至少阅读这些提示: