looping through the same matrix
R
system.time({val=0; for (i in 1:2000){for (j in 1:2000){val=val+a[i,j]}}; val})
user system elapsed
1.862 0.015 1.868
Julia
julia> tic(); val=0; for i in 1:2000; for j in 1:2000; val=val+a[i,j]; end; end; println(val); toc()
5.142821063269366
elapsed time: 0.327145074 seconds
0.327145074
Singular value decomposition of a 2000 x 2000 matrix
> a=matrix(rnorm(4000000),2000)
> system.time(svd(a))
user system elapsed
27.419 0.218 27.452
Julia
julia> tic(); a=randn(2000,2000); toc()
elapsed time: 0.673701438 seconds
0.673701438
julia> tic(); svd(a); toc()
elapsed time: 5.236212822 seconds
5.236212822
No comments:
Post a Comment