Skip to content

Commit 7bfee1f

Browse files
committed
added 2d arrays to benchmarks.
for 2d array `OffsetArray` performance penalty over `Array` is small.
1 parent 838f846 commit 7bfee1f

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

benchmark/benchmarks.jl

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,22 @@ const dim = 1000
55

66
x = Array(Float64, 2*dim)
77
y = OffsetArray(Float64, -dim + 1 : dim)
8+
x2d = Array(Float64, 2*dim, 2*dim)
9+
y2d = OffsetArray(Float64, -dim + 1 : dim, -dim + 1 : dim)
810

9-
fillx(x) = for i in indices(x,1); x[i] = i; end
10-
updatex(x) = for i in indices(x,1); x[i] = x[i] + i; end
11-
updatex_eachindex(x) = for i in eachindex(x); x[i] = x[i] + i; end
11+
fill(x) = for i in indices(x,1); x[i] = i; end
12+
fill2d(x) = for i in indices(x,1); for j in indices(x,2); x[i,j] = i + j; end; end
13+
update(x) = for i in indices(x,1); x[i] = x[i] + i; end
14+
update2d(x) = for i in indices(x,1); for j in indices(x,2); x[i,j] = x[i,j] + i + j; end; end
15+
update_eachindex(x) = for i in eachindex(x); x[i] = x[i] + i; end
1216

13-
@show @benchmark fillx(x)
14-
@show @benchmark fillx(y)
15-
@show @benchmark updatex(x)
16-
@show @benchmark updatex(y)
17-
@show @benchmark updatex_eachindex(x)
18-
@show @benchmark updatex_eachindex(y)
17+
@show @benchmark fill(x)
18+
@show @benchmark fill(y)
19+
@show @benchmark fill2d(x2d)
20+
@show @benchmark fill2d(y2d)
21+
@show @benchmark update(x)
22+
@show @benchmark update(y)
23+
@show @benchmark update2d(x2d)
24+
@show @benchmark update2d(y2d)
25+
@show @benchmark update_eachindex(x)
26+
@show @benchmark update_eachindex(y)

0 commit comments

Comments
 (0)