Skip to content

Commit 838f846

Browse files
authored
Merge pull request #9 from alsam/teh/benchmarks
Faster benchmarks
2 parents 22c4f60 + 4847db3 commit 838f846

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

benchmark/benchmarks.jl

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,13 @@ const dim = 1000
66
x = Array(Float64, 2*dim)
77
y = OffsetArray(Float64, -dim + 1 : dim)
88

9-
fillx() = for i = 1:2*dim x[i] = i end
10-
filly() = for i = -dim+1:dim y[i] = i end
11-
updatex() = for i = 1:2*dim x[i] = x[i] + i end
12-
updatey() = for i = -dim+1:dim y[i] = y[i] + i end
13-
updatex_eachindex() = for i in eachindex(x) x[i] = x[i] + i end
14-
updatey_eachindex() = for i in eachindex(y) y[i] = y[i] + i end
15-
16-
@benchmark fillx()
17-
@benchmark filly()
18-
@benchmark updatex()
19-
@benchmark updatey()
20-
@benchmark updatex_eachindex()
21-
@benchmark updatey_eachindex()
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
2212

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)

src/OffsetArrays.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ Base.eachindex(::LinearFast, A::OffsetVector) = indices(A, 1)
5959
_indices(::Tuple{}, ::Tuple{}) = ()
6060
Base.indices1{T}(A::OffsetArray{T,0}) = 1:1 # we only need to specialize this one
6161

62-
function Base.similar(A::OffsetArray, T::Type, dims::Dims)
62+
function Base.similar{T}(A::OffsetArray, ::Type{T}, dims::Dims)
6363
B = similar(parent(A), T, dims)
6464
end
65-
function Base.similar(A::AbstractArray, T::Type, inds::Tuple{UnitRange,Vararg{UnitRange}})
65+
function Base.similar{T}(A::AbstractArray, ::Type{T}, inds::Tuple{UnitRange,Vararg{UnitRange}})
6666
B = similar(A, T, map(length, inds))
6767
OffsetArray(B, map(indexoffset, inds))
6868
end

0 commit comments

Comments
 (0)