The content of this article is about the execution speed of Julia and Java? The performance comparison between Julia and Java has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
Julia's performance is said to be comparable to c/c. I am very curious about the execution speed of Julia because I have always used Java, so I want to make it simple between Julia and Java. Comparison.
This time, compare the speed of Julia and Java in doing 100 million addition operations.
First of all, the Julia code I wrote was not optimized. Let’s take a look at Julia’s code execution:
x=0 @time for i in 1:10^8 global x+=i end
This is three executions The result: about 6s time
6.550459 seconds (200.00 M allocations: 2.980 GiB, 18.45% gc time) 6.565272 seconds (200.00 M allocations: 2.980 GiB, 18.15% gc time) 6.382583 seconds (200.00 M allocations: 2.980 GiB, 18.37% gc time)
Look at the Java code and execution results:
public class Test1 { public static void main(String[] args) { long t1=System.currentTimeMillis(); long x=0; for(int i = 1; i<=100000000; i++) x+=i; long t2=System.currentTimeMillis(); System.out.println("x="+x+", duration="+(t2-t1)); } }
Three execution results: about 40ms
x=5000000050000000, duration=41 x=5000000050000000, duration=40 x=5000000050000000, duration=40
From the above execution results, Java It is obviously much faster than Julia, with a time difference of more than a hundred times, but this is code that Julia has not optimized. Let's take a look at the situation after Julia optimization
We remove the global variables, put the code into the function, and then call the function. The code is as follows:
function sumfor() x=0 for i in 1:10^8 x+=i end x end @time sumfor() @time sumfor()
The following are the results of three executions. Since Julia will perform precompilation operations in the first execution, we Call the method twice and the second result shall prevail.
The second execution only took 0.002ms, which is much faster than Java.
0.080203 seconds (35.91 k allocations: 1.978 MiB)
0.000003 seconds (5 allocations: 176 bytes)
0.062682 seconds (35.91 k allocations: 1.978 MiB, 46.11% gc time)
0.000002 seconds (5 allocations: 176 bytes)
0.037539 seconds (35.91 k allocations: 1.978 MiB)
0.000002 seconds (5 allocations: 176 bytes)
Summary: From the above comparison, Julia is indeed It is much faster than Java, but only a simple comparison is made here, and no rigorous testing is done. It is for reference only.
The above is the detailed content of What is the execution speed of Julia and Java? Performance comparison of Julia and Java. For more information, please follow other related articles on the PHP Chinese website!