Skip to content

Instantly share code, notes, and snippets.

@carlobaldassi
Created January 7, 2015 09:50
Show Gist options
  • Save carlobaldassi/4513ea697a399c94dd22 to your computer and use it in GitHub Desktop.
Save carlobaldassi/4513ea697a399c94dd22 to your computer and use it in GitHub Desktop.
logical indexing benchmark
function bench()
b = bitrand(500, 500, 300)
i = bitrand(500, 500, 300)
t = vec(bitrand(sum(i)))
c = bitunpack(b)
j = bitunpack(i)
y = bitunpack(t)
println("logical getindex A[I]")
println("---------------------")
println("A::BitArray I::BitArray")
@time b[i]
println("A::BitArray I::Array")
@time b[j]
println("A::Array I::BitArray")
@time c[i]
println("A::Array I::Array")
@time c[j]
println()
println("logical setindex! A[I]=X")
println("------------------------")
println("A::BitArray I::BitArray X::Bool")
@time b[i] = true
println("A::BitArray I::Array X::Bool")
@time b[j] = t
println("A::Array I::BitArray X::Bool")
@time c[i] = t
println("A::Array I::Array X::Bool")
@time c[j] = t
println()
println("A::BitArray I::BitArray X::BitArray")
@time b[i] = t
println("A::BitArray I::BitArray X::Array")
@time b[i] = y
println("A::BitArray I::Array X::BitArray")
@time b[j] = t
println("A::BitArray I::Array X::Array")
@time b[j] = y
println("A::Array I::BitArray X::BitArray")
@time c[i] = t
println("A::Array I::BitArray X::Array")
@time c[i] = y
println("A::Array I::Array X::BitArray")
@time c[j] = t
println("A::Array I::Array X::Array")
@time c[j] = y
nothing
end
bench()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment