diff --git a/test/perf2/bounds.jl b/test/perf2/bounds.jl new file mode 100644 index 0000000000000..75f45a20e4571 --- /dev/null +++ b/test/perf2/bounds.jl @@ -0,0 +1,25 @@ +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" \ No newline at end of file diff --git a/test/perf2/fusion.jl b/test/perf2/fusion.jl new file mode 100644 index 0000000000000..06fc26b8dc275 --- /dev/null +++ b/test/perf2/fusion.jl @@ -0,0 +1,29 @@ +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)