Skip to content

Commit

Permalink
Two new performance tests for #1073: stream fusion and bounds-checking
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy committed Jul 26, 2012
1 parent 89d59e4 commit 6f0b890
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/perf2/bounds.jl
Original file line number Diff line number Diff line change
@@ -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"
29 changes: 29 additions & 0 deletions test/perf2/fusion.jl
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 6f0b890

Please sign in to comment.