[Original title: Julia benchmark against SAS only 50% We need a faster Julia please]
I have read the article :BENCHMARKING JULIA AGAINST PYTHON https://juliacomputing.com/assets/pdf/JuliaVsPython.pdf
So Amazing!
Then I added a benchmark by SAS with Julia, using the sample code in the article. Here are the details:
In Julia
function pi_calcT(n::Int64)
a0::Float64 = 2^0.5
b0::Float64 = 0
p0::Float64 = 2 + 2^0.5
for i in 1:n
a1::Float64 = (a0 + a0^-0.5)/2.0
b1::Float64 = ((1 + b0)*(a0^0.5))/(a0 + b0)
p1::Float64 = ((1 + a1)*p0*b1)/(1 + b1)
a0 = a1
b0 = b1
p0 = p1
end
end
function pi_calc(n)
a0 = 2^0.5
b0 = 0
p0 = 2 + 2^0.5
for i in 1:n
a1 = (a0 + a0^-0.5)/2.0
b1 = ((1 + b0)*(a0^0.5))/(a0 + b0)
p1 = ((1 + a1)*p0*b1)/(1 + b1)
a0 = a1
b0 = b1
p0 = p1
end
end
@timev pi_calc(10^7)
#0.071000 seconds
#elapsed time (ns): 70999817
@timev pi_calcT(10^7)
# 0.071063 seconds
#elapsed time (ns): 71063303
In SAS
1 option fullstimer;
2 /*fcmp function*/
3 proc fcmp outlib=sasuser.funcs.julia;
4 subroutine pi_calc(n);
5 a0=2**0.5;
6 b0=0;
7 p0=2+2**0.5;
8 do i=1 to n;
9 a1=(a0+a0**-0.5)/2.0;
10 b1=((1+b0)*(a0**0.5))/(a0+b0);
11 p1=((1+a1)*p0*b1)/(1+b1);
12 a0=a1;
13 b0=b1;
14 p0=p1;
15 end;
16 endsub;
17 run;
NOTE: Function pi_calc saved to sasuser.funcs.julia.
NOTE: PROCEDURE FCMP used (Total process time):
real time 0.08 seconds
user cpu time 0.04 seconds
system cpu time 0.04 seconds
memory 6810.78k
OS Memory 15848.00k
Step Count 1 Switch Count 0
18 options cmplib=sasuser.funcs;
19 /*run the pi_calc*/
20 data _null_;
21 call pi_calc(10**7);
22 run;
NOTE: DATA statement used (Total process time):
real time 0.30 seconds
user cpu time 0.29 seconds
system cpu time 0.00 seconds
memory 1746.15k
OS Memory 17136.00k
Step Count 2 Switch Count 0
23 /*DATA step for pi_calc*/
24 data _null_;
25 n=10**7;
26 a0=2**0.5;
27 b0=0;
28 p0=2+2**0.5;
29 do i=1 to n;
30 a1=(a0+a0**-0.5)/2.0;
31 b1=((1+b0)*(a0**0.5))/(a0+b0);
32 p1=((1+a1)*p0*b1)/(1+b1);
33 a0=a1;
34 b0=b1;
35 p0=p1;
36 end;
37 run;
NOTE: DATA statement used (Total process time):
real time 0.39 seconds
user cpu time 0.37 seconds
system cpu time 0.00 seconds
memory 782.93k
OS Memory 17136.00k
Step Count 3 Switch Count 0
Whatever I have tried, the performance of Julia is always slower than SAS.
Compare with the data disclosed in the article:
LANGUAGE TIME(SECONDS)
PYTHON_____4.27
JULIA________ 0.82(0.71)
SAS__________ 0.30 in function (0.39 in Data Step)
Julia is So wonderful, such an elegant computer language.
We need it can be Faster and Faster.
Thank you very much for all your efforts! Cheers!