Any alternative will probably not be faster. Your loop already makes only one pass through the array. Julia loops are fast, and there is no speed advantage for vectorized code, as in other languages.
Look at the Julia implementation of the hist function. This is taken directly from Julia 's standard library :
function hist(v::AbstractVector, edg::AbstractVector) n = length(edg)-1 h = zeros(Int, n) for x in v i = searchsortedfirst(edg, x)-1 if 1 <= i <= n h[i] += 1 end end edg,h end
The "edg" parameter contains the edges of the bins. If we remove this function, we get exactly the function that you wrote.
DanielC
source share