diff --git a/examples/gk/gk.jl b/examples/gk/gk.jl index 0ca23c63d97dd..9fe1d50b606ae 100644 --- a/examples/gk/gk.jl +++ b/examples/gk/gk.jl @@ -8,7 +8,7 @@ function myunifskew(n) A = zeros(n, n) - print("A[i,j] initialized with zeros \n"); + #print("A[i,j] initialized with zeros \n"); for i=1:n for j=1:i-1 @@ -28,8 +28,8 @@ function myunifskew(n) end if rem(i,1000) == 0 - print(i) - print("\n") + #print(i) + #print("\n") end end @@ -64,15 +64,15 @@ function gk(n, myeps) csum = zeros(n) - tic() +# tic() while(stop != 1) t=t+1 iter=t #iteration number if rem(iter, 100) == 0 - print(iter) - print("\n") + #print(iter) + #print("\n") end for i=1:n @@ -114,7 +114,7 @@ function gk(n, myeps) end - times[KK] = toc() + times[KK] = 0#toc() iteration[KK] = iter x = X/t @@ -133,7 +133,7 @@ function gk(n, myeps) end if Axepse==n - print(" \n Ax <= eps*e \n") + #print(" \n Ax <= eps*e \n") end #if A*x <= eps*e @@ -148,38 +148,38 @@ function gk(n, myeps) end if errorlmt ==n - print("Assertion condition is satisfied i.e. AX-U<10^-8 \n") + #print("Assertion condition is satisfied i.e. AX-U<10^-8 \n") else print("Error: AX-U<10^-8 not satisfied \n") end #print("welcome") - print("Time for \n") - print(eps) - print("\n") - print("is \n") - print(times[KK]) - print("\n") - print("Number of iteration is \n") - print(iteration[KK]) - print("\n") + # print("Time for \n") + # print(eps) + # print("\n") + # print("is \n") + # print(times[KK]) + # print("\n") + # print("Number of iteration is \n") + # print(iteration[KK]) + # print("\n") end - print("Epsilon vector is \n") - print(myeps) - print("\n") - print("time vector is \n ") - print(times) - print("\n") - print("Iteration Vector is \n") - print(iteration) - print("\n \n") + # print("Epsilon vector is \n") + # print(myeps) + # print("\n") + # print("time vector is \n ") + # print(times) + # print("\n") + # print("Iteration Vector is \n") + # print(iteration) + # print("\n \n") #out = [myeps, time, iteration] #print("Epsilon-Time-Iteration tradeoff \n") #print(out) - print("\n \n") + #print("\n \n") end #end # @profile begin diff --git a/examples/stockcorr.jl b/examples/stockcorr.jl index 58ba80a51b375..5647f6c4dffbe 100644 --- a/examples/stockcorr.jl +++ b/examples/stockcorr.jl @@ -7,7 +7,7 @@ function stockcorr() CurrentPrice = [78. 102.] # Initial Prices of the two stocks Corr = [1. 0.4; 0.4 1.] # Correlation Matrix T = 500 # Number of days to simulate = 2years = 500days - n = 100000 # Number of simulations + n = 3000 # Number of simulations dt = 1/250 # Time step (1year = 250days) Div=[0.01 0.01] # Dividend Vol=[0.2 0.3] # Volatility diff --git a/test/perf2/bounds.jl b/test/perf2/bounds.jl deleted file mode 100644 index 1e26bf577f4c4..0000000000000 --- a/test/perf2/bounds.jl +++ /dev/null @@ -1,25 +0,0 @@ -function laplacian2(A::Matrix, B::Matrix) - d1 = 1 - d2 = size(A,1) - for j = 2:size(B,2)-1 - offset = (j-1)*size(A,1) - for i = 2:size(B,1)-1 - ii = offset+i - B[ii] = A[ii+d1] + A[ii-d1] + A[ii+d2] + A[ii-d2] - 4*A[ii] - end - end -end - -function time_laplacian(A::Matrix, niter::Int) - B = similar(A) - print("Laplacian of a matrix: ") - @time begin - for n = 1:niter - laplacian2(A, B) - end - end -end - -time_laplacian(randn(1000,1000), 100) - -# Note: run time_laplacian with bounds-checking on and off (turn off by commenting out the middle two lines in cgutils.cpp's "emit_bounds_check" diff --git a/test/perf2/fusion.jl b/test/perf2/fusion.jl deleted file mode 100644 index 06fc26b8dc275..0000000000000 --- a/test/perf2/fusion.jl +++ /dev/null @@ -1,29 +0,0 @@ -function arith_vectorized(b,c,d) - a = b.*c + d + 1.0 -end - -function arith_loop(b,c,d) - a = similar(b) - for i = 1:length(b) - a[i] = b[i]*c[i] + d[i] + 1.0 - end -end - -function compare_arith(len::Int, niter::Int) - b = randn(len) - c = randn(len) - d = randn(len) - print("With vectorized: ") - @time begin - for n in 1:niter - a = arith_vectorized(b,c,d) - end - end - print("With loop: ") - @time begin - for n in 1:niter - a = arith_loop(b,c,d) - end - end -end -compare_arith(1_000_000, 10) diff --git a/test/perf2/inline.jl b/test/perf2/inline.jl deleted file mode 100644 index d7820c2b8656a..0000000000000 --- a/test/perf2/inline.jl +++ /dev/null @@ -1,36 +0,0 @@ -function cmp_with_less(x::Vector) - count::Int = 0 - for i = 1:length(x)-1 - if x[i] < x[i+1] - count += 1 - end - end - return count -end - -function cmp_with_func(x::Vector, f::Function) - count::Int = 0 - for i = 1:length(x)-1 - if f(x[i], x[i+1]) - count += 1 - end - end - return count -end - -function compare_inline(len::Int, niter::Int) - x = randn(len) - print("With inline less: ") - @time begin - for n in 1:niter - count = cmp_with_less(x) - end - end - print("With function less: ") - @time begin - for n in 1:niter - count = cmp_with_func(x, isless) - end - end -end -compare_inline(1_000_000, 10) diff --git a/test/perf2/looping.jl b/test/perf2/looping.jl deleted file mode 100644 index cab42a70c9e86..0000000000000 --- a/test/perf2/looping.jl +++ /dev/null @@ -1,40 +0,0 @@ -function testlooping1(p, sz) - index = 1 - for k = 1:sz[3] - for j = 1:sz[2] - jkprod = j*k - for i = 1:sz[1] - p[index] = i*jkprod - index += 1 - end - end - end -end - -function oneloop(p, index::Int, jkprod::Int, imax::Int) - for i = 1:imax - p[index] = i*jkprod - index += 1 - end - return index -end - -function testlooping2(p, sz) - index = 1 - for k = 1:sz[3] - for j = 1:sz[2] - index = oneloop(p, index, j*k, sz[1]) - end - end -end - -sz = (1000,1000,10) -p = Array(Int, sz) -szsmall = (10,10,10) -psmall = Array(Int, szsmall) -testlooping1(psmall, szsmall) -@time testlooping1(p, sz) -p1 = copy(p) -testlooping2(psmall, szsmall) -@time testlooping2(p, sz) -@assert p == p1 diff --git a/test/perf2/perf2.jl b/test/perf2/perf2.jl new file mode 100644 index 0000000000000..b485707ebe40c --- /dev/null +++ b/test/perf2/perf2.jl @@ -0,0 +1,72 @@ +macro timeit(ex,name) + quote + t = Inf + for i=1:5 + t = min(t, @elapsed $ex) + end + println($name, "\t", t*1000) + end +end + +srand(1776) # get more consistent times + +require("$JULIA_HOME/../../examples/list.jl") + +function listn1n2(n1::Int64,n2::Int64) + l1 = Nil{Int64}() + for i=n2:-1:n1 + l1 = Cons{Int64}(i,l1) + end + l1 +end + +@timeit listn1n2(1,10^6) "cons " +gc() + + +# issue #950 +load("$JULIA_HOME/../../examples/gk/gk.jl") +@timeit gk(350,[0.1]) "gk " + +# issue #942 +require("linalg_sparse.jl") +s = sparse(ones(280,280)); +@timeit s*s "sparsemul" + +# issue #939 +y = [500000:-1:1]; +@timeit sortperm(y) "sortperm" + +# issue #938 +x = 1:600000; +@timeit sparse(x,x,x) "sparserang" + +# issue #445 +load("$JULIA_HOME/../../examples/stockcorr.jl") +@timeit stockcorr() "stockcorr" + + +function cmp_with_func(x::Vector, f::Function) + count::Int = 0 + for i = 1:length(x)-1 + if f(x[i], x[i+1]) + count += 1 + end + end + return count +end + +x = randn(200_000) +@timeit (for n in 1:10; count = cmp_with_func(x, isless) end) "funarg " + + +function arith_vectorized(b,c,d) + a = b.*c + d + 1.0 +end + +len = 1_000_000 +b = randn(len) +c = randn(len) +d = randn(len) + +@timeit (for n in 1:10; a = arith_vectorized(b,c,d); end) "vectoriz"