- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Two new performance tests for #1073: stream fusion and bounds-checking
- Loading branch information
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |